javascript - js How to calculate the number of days, hours, minutes and seconds between two timestamps
仅有的幸福
仅有的幸福 2017-05-19 10:12:14
0
3
1285

js How to calculate the number of days, hours, minutes and seconds between two timestamps

仅有的幸福
仅有的幸福

reply all(3)
我想大声告诉你
<script>
    //当前时间与2017-04-04的时间差
    var startTime = "2017-04-04";
    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);
</script>

This is what I wrote before,

仅有的幸福
var start=1491789600000;//2017-4-10 10:00
var end=1494381600000;//2017-5-10 10:00

var utc=end-start;

utc/(24*60*60*1000);//30

同样小时:utc/(60*60*1000);//720小时;

分:utc/(60*1000);
世界只因有你

It is recommended to use third-party momentjs directly. If you think the answer is right, remember to follow fundebug (free full-stack monitoring website)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template