【发布时间】:2014-01-21 01:15:10
【问题描述】:
您好,我正在使用这个时间戳:
function getTimeStamp() {
var now = new Date();
return ((now.getMonth() + 1) + '/' + (now.getDate()) + '/' + now.getFullYear() + " " + now.getHours() + ':'
+ ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes())) + ':' + ((now.getSeconds() < 10) ? ("0" + now
.getSeconds()) : (now.getSeconds())));
}
并在此处节省暂停时间:
localStorage["TmpPause"] = getTimeStamp();
比一段时间后的读取时间和比较:
var pauseTime = localStorage["TmpPause"];
var resumeTime = getTimeStamp();
var difference = resumeTime.getTime() - pauseTime.getTime(); // This will give difference in milliseconds
var resultInMinute = Math.round(difference / 60000);
alert(resultInMinute);
目前我无法计算包括时间在内的 2 个日期之间的差异。我收到错误 undefined is not a function resumeTime.getTime() ???
感谢您的帮助。
【问题讨论】:
-
“时间戳”的格式不符合任何常见的编程用途。最好使用标准化的东西(例如 ISO 8601)。
标签: javascript time