function formatterDate (date) {
let result = new Date(date);
return result;
}
function getTime(starttime,endtime){
var dateDiff = endtime.getTime() - starttime.getTime(); //時間差的毫秒數
var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //計算出相差天數
console.log(dayDiff + "天 ")
}
starttime和endtime格式為 Tue Sep 29 2020 08:00:00 GMT+0800 才能用下面的方法
function calculationTime(starttime,endtime) {
var runTime;
runTime = parseInt((endtime.getTime() - starttime.getTime()) / 1000);
var years = Math.floor(runTime / 86400 / 365);
runTime = runTime % (86400 * 365);
var moths = Math.floor(runTime / 86400 / 30);
runTime = runTime % (86400 * 30);
var days = Math.floor(runTime / 86400);
runTime = runTime % 86400;
var hour = Math.floor(runTime / 3600);
runTime = runTime % 3600;
var minute = Math.floor(runTime / 60);
runTime = runTime % 60;
var second = runTime;
console.log(years ,moths ,days,hour ,minute ,second );
};