您可以使用添加、减去以及执行许多其他操作nativeJavaScriptDate目的。它是足够强大满足您的大部分需求。如果使用它,您可以节省数千字节的页面大小,并使每个人都可以理解代码(可能 90% 的 JavaScript 开发人员从未使用过任何插件来计算日期)
我讨厌 Date 对象的一点是它没有内置格式化输出.
例如,如果不进行字符串解析,您将无法得知本地化的星期几或月份名称。然后datejs来帮助你。
Date 对象可以做什么?
var msMinute = 60*1000,
msDay = 60*60*24*1000,
a = new Date(2012, 2, 12, /* days, hours*/ 23, 59, 59),
b = new Date("2013 march 12"), /* string */
c = new Date(), /* now */
d = new Date(c.getTime() + msDay - msMinute); /* tomorrow - minute */
console.log(a.getUTCHours());
console.log(typeof (b - a + 1000));
console.log(Math.floor((b - a) / msDay) + ' full days between');
console.log(Math.floor(((b - a) % msDay) / msMinute) + ' full minutes between');
console.log('Today is ' + c.getDay() + ' day of week');
console.log('Tomorrow is ' + d.getDay() + ' day of week');
console.log('Your timezone offset is ' + c.getTimezoneOffset() + ' minutes');
轻松计算圣诞节前的天数
And, sometimes there is more truth in a joke then you could ever expect