What's the difference between ISO 8601 and RFC 3339 Date Formats?

DatetimeFormatWeb Standards

Datetime Problem Overview


ISO 8601 and RFC 3339 seem to be two formats that are common the web. Should I use one over the other? Is one just an extension? Do I really need to care that bad?

Datetime Solutions


Solution 1 - Datetime

> Is one just an extension?

Pretty much, yes - RFC 3339 is listed as a profile of ISO 8601. Most notably RFC 3339 specifies a complete representation of date and time (only fractional seconds are optional). The RFC also has some small, subtle differences. For example truncated representations of years with only two digits are not allowed -- RFC 3339 requires 4-digit years, and the RFC only allows a period character to be used as the decimal point for fractional seconds. The RFC also allows the "T" to be replaced by a space (or other character), while the standard only allows it to be omitted (and only when there is agreement between all parties using the representation).

I wouldn't worry too much about the differences between the two, but on the off-chance your use case runs in to them, it'd be worth your while taking a glance at:

Solution 2 - Datetime

There are lots of differences between ISO 8601 and RFC 3339. Here is some examples to give you an idea:

2020-12-09T16:09:53+00:00 is a date time value that is compliant by both standards.

2020-12-09 16:09:53+00:00 uses a space to separate the date and time. This is allowed by RFC 3339 but not allowed by ISO 8601.

2020-12-09T16:09:53-00:00 specifies a negative zero in the time offset. This is allowed by RFC 3339 but not allowed by ISO 8601.

20201209T160953Z omits the hyphens and colons. This is allowed by ISO 8601 but not allowed by RFC 3339.

ISO 8601 allows for things like ordinal dates such as 2020-344 which represents the 344th day of year 2020. RFC 3339 doesn't allow for that.

For your questions:

> Is one just an extension?

No. As shown above each standard supports syntax variations not supported by the the other standard. So one syntax is not a superset or an extension of the other.

> Should I use one over the other?

Of course this depends on your scenario. A safe general strategy is to generate date time strings that are valid by both standards.

Another good general strategy is to use an existing standard library for parsing/formatting date time strings and not write custom implementations unless you are addressing a genuinely custom scenario.

> Do I really need to care that bad?

Well, that's up to you. Most regular developers who deal with date time strings should have a high level understanding but don't need to dive into the details.

Solution 3 - Datetime

RFC 3339 is mostly a profile of ISO 8601, but is actually inconsistent with it in borrowing the "-00:00" timezone specification from RFC 2822. This is described in the Wikipedia article.

Solution 4 - Datetime

It seems difficult and/or expensive to actually get access to the ISO spec. Which is why we see many links to the wikipedia page instead.

For this reason alone I prefer the RFC3339: you can go straight to primary source.

Solution 5 - Datetime

You shouldn't have to care that much. RFC 3339, according to itself, is a set of standards derived from ISO 8601. There's quite a few minute differences though, and they're all outlined in RFC 3339. I could go through them all here, but you'd probably do better just reading the document for yourself in the event you're worried:

https://www.rfc-editor.org/rfc/rfc3339

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrig LamoreauxView Question on Stackoverflow
Solution 1 - DatetimeConroyPView Answer on Stackoverflow
Solution 2 - DatetimeclayView Answer on Stackoverflow
Solution 3 - DatetimeZeframView Answer on Stackoverflow
Solution 4 - Datetimejojo hohanonView Answer on Stackoverflow
Solution 5 - DatetimeDavid MortonView Answer on Stackoverflow