Javascript日期方法不一致 - getDate vs getMonth [英] Javascript Date method inconsistency - getDate vs getMonth
问题描述
我明白为什么很难改变现在的行为,但是有这样的理由是这样设计的这在第一位?
文档可以在这里找到: http ://www.w3schools.com/jsref/jsref_obj_date.asp
我想几个月是0因为 Java做了同样的事情方式 JavaScript语言设计时。
编辑 Oracle取代了较旧的Java文档,有一个该页面的归档版本。
This caused me a bit of a headache last night and I wanted to understand why the getDate method in the Date object is 1 based (returns values from 1-31) while the getMonth method is 0 based (returns 0-11). I'm wondering why there is this inconsistency in methods for the same object.
I understand why it's difficult to change the behavior now but are there any reasons this was designed like this in the first place?
Documentation can be found here: http://www.w3schools.com/jsref/jsref_obj_date.asp
I suppose months are 0-based because Java did it the same way when the JavaScript language was designed.
EDIT Oracle took down older Java documentation, there is an archived version of that page.
这篇关于Javascript日期方法不一致 - getDate vs getMonth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!