I believe that the difference is caused by Date.parse
adding UTC to one string but not the other, namely: /
is not a legal separator in Date.parse() which means that UTC isn't added to the time once it's parsed. Because '
is a legal separator, it is parsed and then UTC is added to the returned time.
Date.parse
is used by the new Date()
method and its implementation is browser specific, I'm surprised this sort of thing doesn't come up more often.
The specification for Date.parse
says:
The String may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first attempts to parse the format of the String according to the rules called out in Date Time String Format (15.9.1.15). If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.
So I'd suggest either adding in a timezone manually before you parse, or discarding the time returned by new Date()
, however that could lead to issues around midnight etc. The safest thing would be to see if you can get the date in a more specific format from both systems, with timezone information.
1st - 2nd == 0
I was not getting anyTrue
. I can control for this of course but it mkaes life more complicated – Simon H