现在的位置: 首页 > 综合 > 正文

js 中使用getUTCMonth() 与 getMonth() 区别

2013年06月12日 ⁄ 综合 ⁄ 共 411字 ⁄ 字号 评论关闭

getUTCMonth() 与 getMonth() 正常情况下返回的都是当前月份减1的值,

先看结果:

var date = new Date();
date.setHours(0,0,0,0);
console.log('getMonth():'+date.getMonth() +'date:'+date);
console.log('getUTCMonth():'+date.getUTCMonth() +'date:'+date);
date.setDate(1);
date.setHours(0,0,0,0);
console.log('getMonth():'+date.getMonth() +'date:'+date);
console.log('getUTCMonth():'+date.getUTCMonth() +'date:'+date);

UTC在那天返回了3,也就是4月份。这个跟date打印出来的不一样,具体什么问题,以后再补充。

抱歉!评论已关闭.