Date function in JavaScript creating Wrong month? [Solved]

Question: While using Date function in JavaScript, the month created is wrong. For example, for displaying the month of November, I pass ’11’ as an argument to the date function. But the result is December. Below is the function reference and its possible arguments.

new Date(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]);

E.g:, var sampleDate = new Date(2016, 11, 15, 0, 0, 0,0);

Sample output : Tue Dec 15 2016 00:00:00

Can you please explain this behavior?


date function

The behavior is right. The Date function in JavaScript will start with zero (0). Hence, the 10th month is November and 11th month is December. The month field is an integer value, starting with 0 for January and 11 for December. That’s weird isn’t? But that’s how it is.

Reference: JavaScript reference.

Topics :

vps germany

Get Free Email Updates

Disclaimer: The content published in this article is the views of the author only. Techglimpse does not gurantee accuracy, completness or validity. If you believe the content on this post violates your copyright, please send us a mail for removal. Read more.