Search code examples
timezoneutciso8601timezone-offset

Is it better to present time with offset, or time as UTC?


I have a web API that can return time zone-aware time data in the form of an ISO 8601 compliant string. I have two options, return time data with an offset, and return time data converted to UTC (Zulu time).

Example, I want to return a time of 5/6/2014 5:16:00 PM Eastern Time.

Option 1: "2014-05-06T17:16:00-04:00"

Option 2: "2014-05-06T21:16:00Z"

Which is the better option? Which is the more popular option?

My customer is fine with either way. But I would like to have your opinion on which is the better option, and your reasoning behind your preference.

I think option 1 is better since it provides additional information about the time zone. In this example, assuming all parties are in the US, you know the time zone is Eastern Time based on the date and the -4:00 offset.


Solution

  • It very much depends on what your API is trying to represent. Context is key

    • If all you need to represent is "the exact point in time something happened", then send back the value adjusted to UTC, with the trailing Z.

      Example: The time recorded that a user hit a particular page on your web site.

    • If you need to represent that something happened with respect to a particular local time, then send back that local time, with a trailing offset.

      Example: The time that an employee clocks in for work.

    Either option are valid ISO-8601 formats, and both represent a distinct moment in time. The only difference is that the local+offset format retains the perspective of the original observer.

    See also DateTime vs DateTimeOffset.