function getNowDate(type=0) { let date = new Date(); let year = date.getFullYear(); //年 let month = date.getMonth() + 1; //月 let day = date.getDate(); //日 let hour = date.getHours(); //时 let minutes = date.getMinutes(); //分 let seconds = date.getSeconds(); //秒 if (month > 1 && month <= 9) month = "0" + month; if (day > 0 && day <= 9) day = "0" + day; if (hour > 0 && hour < 9) hour = "0" + hour; if (minutes > 0 && minutes <= 9) minutes = "0" + minutes; if (seconds > 0 && seconds < 9) seconds = "0" + seconds; if(type==0){ return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`; }else if(type==1){ return `${year}年${month}月${day}日`; } } //比较两时间之差 function DifferDate(Date1, Date2) { if (typeof(Date1) == "string") Date1 = Date.parse(Date1); if (typeof(Date2) == "string") Date2 = Date.parse(Date2); return Math.floor((Date1 - Date2) / (24 * 3600 * 1000)); } function GetTime(data){ let cdata = JSON.parse(data); if(cdata[0]==cdata[1])return cdata[0]; let sp1 = cdata[0].split('-') let sp2 =cdata[1].split('-') if(sp1[0]==sp2[0]){ if(sp1[1]==sp2[1]){ return `${sp1[0]}-${sp1[1]}-${sp1[2]} 至 ${sp2[2]}` }else{ return `${sp1[0]}-${sp1[1]}-${sp1[2]} 至 ${sp2[1]}-${sp2[2]}` } }else{ return cdata[0]+" 至 "+cdata[1] } } export { getNowDate, DifferDate, GetTime, }