snippetgoCritical
How to convert ISO 8601 time in golang?
Viewed 0 times
howtimeconvert8601golangiso
Problem
What is the equivalent code in golang for the following shell command ?
date -u +%Y-%m-%dT%T%zSolution
If you're looking for a simple, but not perfect solution consider using
See https://ijmacd.github.io/rfc3339-iso8601/ for differences and also has a handy test file generator to show differences. There is also a good discussion on SO here What's the difference between ISO 8601 and RFC 3339 Date Formats?
golang Time.Format
time.RFC3339 constant. But also know that there are differences between ISO8601 which are too complex for this answer.See https://ijmacd.github.io/rfc3339-iso8601/ for differences and also has a handy test file generator to show differences. There is also a good discussion on SO here What's the difference between ISO 8601 and RFC 3339 Date Formats?
package main
import (
"time"
"fmt"
)
func main(){
fmt.Println(time.Now().Format(time.RFC3339))
}golang Time.Format
Code Snippets
package main
import (
"time"
"fmt"
)
func main(){
fmt.Println(time.Now().Format(time.RFC3339))
}Context
Stack Overflow Q#35479041, score: 284
Revisions (0)
No revisions yet.