24

I've been doing work with parsing datetime strings for our international application. I'm running into an interpretation issue that I can't seem to find a definitive answer. Should an ISO 8601 datetime string without a timezone component be treated as local time?

Per wikipedia (which I don't want to base my business decisions off of):

If no UTC relation information is given with a time representation, the time is assumed to be in local time.

However, I can't find supporting documentation via ISO or any other generally acceptable source of truth. Everything that I've found talks about how to handle offsets for local time (e.g. +/- 0500, etc). Assuming local time in these cases would help me substantially as my users can submit the same date for all regions without needed to calculate the specific offset for each region.

For example:

2012-01-01T00:00:00 # Convert to local
2012-01-01T00:00:00Z # Zulu/UTC...don't convert

Is there an established interpretation for timezone-less ISO 8601 strings?

2 Answers 2

28

Section 4.2.2 of ISO 8601 gives examples with no TZ designator saying they are local times. 4.2.4 says UTC times use the 'Z' designator. Of course it always raises the question "local time where?"...

The zone designator is empty if use is made of local time in accordance with 4.2.2.2 through 4.2.2.4, it is the UTC designator [Z] if use is made of UTC of day in accordance with 4.2.4 and it is the difference-component if use is made of local time and the difference from UTC in accordance with 4.2.5.2.

1
  • 1
    Awesome, this is what I was looking for. It's kind of lame that the ISO documentation isn't "publicly" available for free, which is why I missed it the first time. God bless people who upload it anyway :) There is an inherent attribute in the user input that specifies region, so the "where" aspect is already taken care of.
    – Devin
    Oct 14, 2015 at 15:55
-1

Without the timezone designator, the datetime string will be interpreted as local time -- but as local time to the SERVER.

If your users are in different timezones, the dates they submit without TZ information will be interpreted incorrectly with your local TZ offset.

4
  • Who says it has to be interpreted as the local time of the server, and not some other appropriate place?
    – fabspro
    Oct 14, 2022 at 11:21
  • 1
    Let me be more precise: it will be interpreted as local time of the environment where you're running the code. If the code is running on the backend, the dates will be interpreted with the TZ offset local to the server. If the server is in a different timezone than the client, you will be confused.
    – btk
    Oct 19, 2022 at 14:18
  • I would still say this is application-specific. Local time is local time, it does not have a time zone unless and until one is added.
    – fabspro
    Oct 20, 2022 at 8:05
  • But yes, if you start doing operations on a local date, many libraries will interpret a local date/time as if it was in the local computer's timezone by convention I suppose!
    – fabspro
    Oct 20, 2022 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.