How to handle ISO 8601 timestamp in GoLang?

I know that I need to use the temporary layout in GoLang (as shown here https://golang.org/src/time/format.go ), but I can not find the layout for the ISO 8601 timestamp.

If this helps, I get the timestamp from the Facebook API. Here is an example timestamp:2016-07-25T02:22:33+0000

+4
source share
4 answers

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

+4
source

RFC3339 is equivalent to ISO 8601. In particular, it has the same format, RFC3339 has more stringent requirements (for example, it requires a full date representation with a 4-digit year).

ISO 8601 RFC 3339?

, time.RFC3339 .

+1

, RFC3339 , "+00: 00" ( "Z" UTC), ISO8601 "+0000".

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

, time.RFC3339

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

:

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

, Cocoa Swift 4 Date JSON .iso8601:

let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .iso8601
if let encodedData = try? encoder.encode(myStruct) {
    ...
}

Go :

2006-01-02T15:04:05.99999Z07:00
0

Source: https://habr.com/ru/post/1649192/


All Articles