年月日时分秒处理时间差

it2023-05-08  76

年月日时分秒处理时间差—标准的时间格式处理时间差

例如: 2020-10-16 15:55:03

// 开始的时间 2020-10-20T15:05:54Z 需要处理开始时间的格式 var start_time = "2020-10-20T15:05:54Z"; // 处理开始时间的时间格式函数 function rTime(date) { var json_date = new Date(date).toJSON(); return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') } let startTime = rTime(start_time); // console.log(startTime) // 处理开始时间为标准格式:2020-10-16 15:55:03 //计算时间差函数 function calculationTime(startTime_a) { var s1 = new Date(startTime_a.replace(/-/g, "/")), //当前时间为s2 s2 = new Date(), runTime = parseInt((s2.getTime() - s1.getTime()) / 1000); var year = Math.floor(runTime / 86400 / 365); runTime = runTime % (86400 * 365); var month = Math.floor(runTime / 86400 / 30); runTime = runTime % (86400 * 30); var day = 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; //返回相差时间: 年 月 日 时 分 秒 var shijiancha = new Array(year,month,day,hour,minute,second) return shijiancha } //计算出startTime与当前的时间差 let shijiancha_a = calculationTime(startTime) console.log(shijiancha_a)// [0, 0, 0, 0, 24, 15]
最新回复(0)