jotapdiez
jotapdiez

Reputation: 1466

What can make Date.parse return different values?

I have a slight difference on two machines with the same parameter for Date.parse function.

I run javascript:Date.parse('11/10/2014 00:00:00 AM') (month/day/year time) on the address bar of IE (10 and 8) and FF (latest) and the result is:

Machine 1: 1415588400000

Machine 2: 1415584800000

Without the hour/minute/seconds the result is the same.

Both machines are Windows 7 Professional but the Machine 2 have been recently updated from Windows Vista to Windows 7. Before the update, this command worked. Also, Machine 2 has only one installed update and Machine 1 has something like 200 updates installed.

Both machines have the same configuration about time and dates (formats, time Zone, etc)

What can cause the difference on Date.parse on two machines with same Time Zone?

EDIT: I'm from Argentina and both machines have Time Zone: (UTC-03:00) Buenos Aires

Upvotes: 2

Views: 139

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241959

This is a compound issue.

  • Argentina used to have daylight saving time, back in 2009. From 2010 forward, they no longer have it. Reference Here.

  • JavaScript has a known issue with not using the correct DST rule, but just the most current rule it knows about. Details Here.

  • The machine that is returning 1415584800000 is using UTC-2 instead of UTC-3 because it did not get the update which added the new rule for 2010 forward. It is still using 2009's rule, which would place this date into daylight saving time.

    This updated was included in KB976098 - the December 2009 cumulative time zone update for Windows.

You can verify this by looking in the registry at the following location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Argentina Standard Time\Dynamic DST

With the update applied, it should look like this:

Registry Screenshot

Without the update, it will not have the entry for 2010.

You should always apply time zone updates - either automatically from Windows Update, or by watching the anouncment list at microsoft.com/time.

Upvotes: 1

Royi Namir
Royi Namir

Reputation: 148744

What can cause the difference on Date.parse

Time zones , user localization environment.

If you want to use dates (trustfully) either use :

  • Moment.JS
  • ISO format which is yyyy-mm-ddThh:mm:ss[+xy:zp]
  • Split it manually via / and create a new Date with each argument to its place.

As to your question :

Date.parse('2014-11-10T00:00:00Z')

Will work in all browsers with the same value. notice It's UTC.

But,(if you need) - just add time zone eg:

Date.parse('2014-11-10T00:00:00+03:00')

And if you want a date object out of it :

new Date(Date.parse('2014-11-10T00:00:00+03:00'))

Upvotes: 2

Related Questions