Javascript Date.parse and Date.UTC give different results

Can someone explain to me why?

d = Date.parse('8/15/2012 '+'11:59:45 AM'); alert(d); alert(Date.UTC(2012, 7, 15, 11, 59, 45)); 

+4
source share
2 answers

Date.parse assumes local time, if not specified.

However, UTC is obviously UTC.

For example, my computer is UTC -5 (well, actually, Chicago CDT), so for two timestamps it seems to me like 5 hours.

You will get the same if you specify UTC:

 Date.parse('8/15/2012 '+'11:59:45 AM UTC'); //1345031985000 Date.UTC(2012, 7, 15, 11, 59, 45); //1345031985000 
+7
source

I assume the month difference was a typo in your question.

Date.parse returns the difference between the date and midnight of January 1, 1970.

Date.UTC returns the difference between your date and midnight January 1, 1970 GMT .

If your time zone is set to GMT (UTC), you should expect to see the same value that was returned by both calls.

-1
source

All Articles