Why There Is Need To Add 1 To The Month For This Date Conversion?
Solution 1:
That's legacy of C. The month in timestamps are zero-based.
Compare Date.getMonth():
The value returned by getMonth is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
int tm_mon month of year [0,11]
And why the months start with zero in many programming languages is explained in here: Zero-based month numbering. Paraphrased: Using January == 0 was useful in ancient times, and now we re stuck with it.
Solution 2:
http://www.w3schools.com/jsref/jsref_getmonth.asp
The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.
Note: January is 0, February is 1, and so on.
Solution 3:
The month range is 0-11. i.e. For January it will be 0 and for December it will return you 11. Therefore we need to add 1 to it.
Post a Comment for "Why There Is Need To Add 1 To The Month For This Date Conversion?"