为什么 JavaScript 的 Date 构造函数中的月份参数范围从 0 到 11? [英] Why does the month argument range from 0 to 11 in JavaScript's Date constructor?

查看:20
本文介绍了为什么 JavaScript 的 Date 构造函数中的月份参数范围从 0 到 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用下面的调用在 JavaScript 中初始化一个新的 Date 对象时,我发现月份参数从零开始计数.

When initializing a new Date object in JavaScript using the below call, I found out that the month argument counts starting from zero.

new Date(2010, 3, 1);  // that's the 1st April 2010!

为什么月份参数从 0 开始?另一方面,月份参数(最后一个)是从 1 到 31 的数字.这有充分的理由吗?

Why does the month argument start from 0? On the other hand, the day of the month argument (last one) is a number from 1 to 31. Are there good reasons for this?

推荐答案

这是编程世界中一个古老的(可能是不幸的,可能正在消亡)传统,请参阅旧标准 (POSIX) localtime C 函数http://linux.die.net/man/3/localtime

It's an old (probably unfortunate, probably dying) tradition in the programming world, see the old standard (POSIX) localtime C function http://linux.die.net/man/3/localtime

这篇关于为什么 JavaScript 的 Date 构造函数中的月份参数范围从 0 到 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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