我需要使用 Javascript 以这种格式获取时差:“HH:MM:SS”。
我试过这个:
var diff = Date.parse( time2) - Date.parse( time1 );
var total_time = (diff / 1000 / 60 / 60) + ":" + (diff / 1000 / 60) + ":" + (diff / 1000);
还有这个:
var diff = new Date( time2) - new Date( time1 );
var total_time = (diff / 1000 / 60 / 60) + ":" + (diff / 1000 / 60) + ":" + (diff / 1000);
这些是 time2 和 time1 的值:
time1: "2012-11-07 15:20:32.161"
time2: "2012-11-07 17:55:41.451"
在这两种情况下我得到的结果是:
total_time= 0.5250819444444444:31.504916666666666:1890.295
你可以看到是不正确的