480

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?

3

5 Answers 5

369

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:

7
  • 29
    Sorry Java Guy, but that's not quite correct. The appendix you refer to is informational only and the restriction is for the sake of keeping the grammar simpler. The note at the end of section 5.6 clearly states that a space may be used for the sake of readability, referring to the earlier mention of readability which is the subject of section 5.2. to quote: "Applications using this syntax may choose, for the sake of readability, to specify a full-date and full-time separated by (say) a space character." Aug 15, 2014 at 22:16
  • 10
    @JavaGuy The appendix you've linked to isn't even talking about the RFC 3339 syntax - it's titled ISO 8601 Collected ABNF and is an attempt to formally describe the grammar of ISO 8601 using ABNF. Nothing it says should be taken as evidence about the RFC 3339 datetime syntax.
    – Mark Amery
    Jun 7, 2015 at 21:29
  • 4
    FWIW: It has been discussed on the coreutils list: lists.gnu.org/archive/html/bug-coreutils/2006-05/msg00019.html Sep 27, 2016 at 13:53
  • 4
    "RFC 3339 requires a complete representation of date and time" - This is not correct. Please consider editing the answer. I emailed one of the RFC authors just to be completely sure. The reply includes "I think it's perfectly fair game to reference the [RFC3339] 'full-date' syntax production if you want just a date stamp. … maybe an erratum might be in order" Also, JSON Schema v7 has explicit support for RFC 3339 date-only (full-date) and time-only (full-time) profiles. json-schema.org/draft-07/json-schema-release-notes.html. Feb 4, 2019 at 4:48
  • 21
    I'm the author that Justin (previous comment) contacted (though not responsible for most of the heavy lifting there). I confirm his comment. Generally, I would suggest specification documents like RFC3339 specify rather than require - it's the context of use that determines what is required. As long as it's clear what is intended, then referencing a specific syntax production is fine. (This is not really different to what RFC3339 itself does in making selective reference to ISO8601.) See also the NOTE in section 5.6. Feb 4, 2019 at 10:14
127

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.

1
  • The first example is inverted. RFC 3339 requires the T (or discouraged but allowed t), but NOT a space. ISO-8601 allows a space. Jan 26 at 2:40
22

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.

6

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.

0

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

0

Your Answer

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