javascript日期创建,无法设置正确的月份 [英] javascript date creation, can't set the correct month

查看:47
本文介绍了javascript日期创建,无法设置正确的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var d = new Date(2011,1,1);

alert(d);

此警报为2月,而应为1月

this alert says February, while it should say January

有人对此有一些解释吗?

anybody has some explanation for that ?

推荐答案

JavaScript Date对象零索引月份.

JavaScripts Date object zero-indexes months.

尝试:

var d = new Date(2011,0,1);

alert(d);

相反.

有关更多信息,请参见文档

See the documentation for more info!

这篇关于javascript日期创建,无法设置正确的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆