getMonth() trap in Javascript

by Matti Lehtinen December 14, 2009 19:07

In .NET DateTime.Month returns the month as integer between 1 and 12. Corresponding thing in JavaScript is Date.getMonth() but values are from 0 to 11.

Ok, it is common to start indexing from zero but the confusing part is that JavaScript’s Date.getDate() returns values from 1 to 31 so it is not analogous to getMonth(). Be aware of that trap when playing with dates in JavaScript.

Tags:

JavaScript

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant