我正在尝试获取特定日期的确切秒数,分钟数等。这可能听起来很愚蠢,但为什么结果加倍?那似乎不对,是吗?
setInterval(function() {
var startDate = new Date(),
startDateTime = startDate.getTime(),
endDate = new Date(2012, 5, 14),
endDateTime = endDate.getTime();
var timeLeft = endDateTime - startDateTime;
var seconds = Math.round(timeLeft / 1000),
minutes = Math.round(seconds / 60),
hours = Math.round(minutes / 60),
days = Math.round(hours / 24),
weeks = Math.round(days / 7);
console.log(weeks, days, hours, minutes, seconds);
}, 1000);
答案 0 :(得分:4)
JavaScript Date构造函数就像Java一样 - Days和Years是基于1的,但月份是从零开始的。所以2015年2月10日的日期是:
var aDate= new Date(2015,1,10);