Javascript date.utc problem

I am trying to compare 2 dates using javascript. 1 at the end of the month and 1 at the beginning. I need to compare these 2 dates in seconds, so I am using the javascript Date.UTC function.

Here is the code:

var d = Date.UTC (2010,5,31,23,59,59);
document.write (d);

var d2 = Date.UTC (2010,6,1,12,20,11);
document.write (d2);

Output for:

1278028799000
1277986811000

This tells me that 1/6/2010 is less than 5/31/2010 in milliseconds.

How is this possible? What am I doing wrong?

Thank you for your help.

+3
source share
1 answer

The parameter monthfor Date.UTC()has a 0-index; January - 0, February - 1, etc.

UTC() , "31 2010 " "1 2010 ". 23:59:59 .

+7

Source: https://habr.com/ru/post/1747091/


All Articles