How do I parse an ISO 8601 Timestamp in GoLang?

I found this layout to work: "2006-01-02T15:04:05-0700"


The problem here is that RFC3339 requires the zone offset to be given as "+00:00" (or "Z" in case of UTC) while ISO8601 allows it to be "+0000".

From RFC3339:

[...]

time-numoffset  = ("+" / "-") time-hour ":" time-minute
time-offset     = "Z" / time-numoffset

[...]

full-time       = partial-time time-offset
date-time       = full-date "T" full-time

So instead of the time.RFC3339 layout

"2006-01-02T15:04:05Z07:00"

you have to use:

"2006-01-02T15:04:05Z0700"

RFC3339 is equivalent to ISO 8601. Specifically, it has identical format, RFC3339 just has stricter requirements (example, it requires a complete date representation with 4-digit year).

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

So you can use the constant time.RFC3339 as your layout.

Tags:

Time

Timestamp

Go