js 获取两个时间戳之间相隔多少天多少小时多少分多少秒

<script>
function getRemainderTime (startTime){
var s1 = new Date(startTime.replace(/-/g, "/")),
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;
// console.log(year,month,day,hour,minute,second);
  return year+','+month+','+day+','+hour+','+minute+','+second; }
//当前时间与2018-05-10的时间差
var startTime = "2018-05-10";
console.log(getRemainderTime(startTime)); </script>

  

js 获取两个时间戳之间相隔多少天多少小时多少分多少秒

上一篇:《Python数据分析与挖掘实战》一2.2 Python使用入门


下一篇:c++ primer plus 习题答案(8)