billy_comic billy_comic - 2 months ago 6
AngularJS Question

How To Pass Dates In Zulu Format So They Will Work Regardless Of TimeZone

I'm passing a date into a backend function that performs several processes. I have users reporting that they are getting failures from different time zones (more specifically overseas, but a couple others from the coasts). So I'm trying to format my date/time to ZULU time to allow those users to get success regardless of their time zone.

Below are the formats that I have built to pass into the function to solve the issue. The one that is at 05 hours works fine, but the one that is at 00 (which is what I understand to be timezone agnostic) is failing.

THIS FAILS
1960-08-02T00:00:00:000Z

THIS WORKS
1960-08-02T05:00:00.000Z

Can someone with some date conversion javascript experience tell me why this would be the case?

Thanks,
B

Answer

Because the format of both is different:

1960-08-02T00:00:00:000Z
                   ^ colon
1960-08-02T05:00:00.000Z
                   ^ period

You should use the latter format (see also the spec), with which you'll find that 1960-08-02T00:00:00.000Z will be accepted as well.

Comments