Timestamp with Z designator / RFC3339 / ISO8601

Hello all,

I have a problem with Go Time.Format especially with RFC3339 and RFC3339Nano

if you check RFC3339 section 5.6 (https://tools.ietf.org/html/rfc3339#section-5.6) it’s clearly state by the ABNF definition that Z and the ±hh:mm time offset are alternatives

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

Please check https://en.wikipedia.org/wiki/Augmented_Backus–Naur_form#Alternative

and also if you check https ://en.wikipedia.org/wiki/ISO_8601#Coordinated_Universal_Time_(UTC) and https ://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC both section explains that Z is an alternative form of +00:00 time offset (a.k.a. UTC)

Go Time.Format documentation (https ://pkg.go.dev/time?pkg-constants) states:

Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus:

Z0700  Z or ±hhmm
Z07:00 Z or ±hh:mm
Z07    Z or ±hh

IMHO that is absolutely false. Both RFC3339 and ISO8601 states the opposite.

Why was this Z0700 Frankenstein-like format implemented instead of the correct format from RFC3339 / ISO 8601?

PS: Sorry for the broken URLs above but the forum engine says new users not allowed to put more than 2 URLs in the post

If you use Z0700 in the format string, then you will either get Z if the offset is zero or ±hhmm if it is non.zero.

Similarily for Z07:00 and Z07.

Therefore I do not understand you question. It is still an alternative and you will never see Z0700 in a formatted sstring.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.