Javascript getUTCMonth()在12月返回0? [英] Javascript getUTCMonth() returns 0 for December?

查看:86
本文介绍了Javascript getUTCMonth()在12月返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的小提琴在12月返回0

MY fiddle here is returning 0 for December

http: //jsfiddle.net/3CpXz/

var exploded = "2011-12-25".split('-');
var d = new Date(exploded[0], exploded[1], exploded[2]);
document.write("year"+d.getUTCFullYear()+ " month"+d.getUTCMonth()+" day"+d.getUTCDate());

为什么会这样?

推荐答案

不,这是另一种方式:您定义的日期就像是在1月份

No, this is the other way around: you are defining date as if it was in January.

请参阅 日期()上的文档

See the documentation on Date():


- 表示月份的整数值,从0开始表示1月份到12月11日。

month - Integer value representing the month, beginning with 0 for January to 11 for December.

您提供了 12 ,因此被视为 0 (1月)。

You provided 12, so it was treated as 0 (January).

如果您需要证明,请参阅修改后的脚本版本,显示整个日期和时间

这篇关于Javascript getUTCMonth()在12月返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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