Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ISO 8601 time in golang?

Tags:

go

What is the equivalent code in golang for the following shell command ? date -u +%Y-%m-%dT%T%z

like image 759
codefx Avatar asked Feb 18 '16 10:02

codefx


People also ask

How do I convert a date to ISO 8601?

The date. toISOString() method is used to convert the given date object's contents into a string in ISO format (ISO 8601) i.e, in the form of (YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss.

What time zone is ISO 8601?

Universal Coordinate Time is the time at the zero meridian, near Greenwich, England. UTC is a datetime value that uses the ISO 8601 basic form yyyymmddT hhmmss+|– hhmm or the ISO 8601 extended form yyyy-mm-ddT hh:mm:ss+|– hh:mm.

What is Z in ISO 8601 date format?

Coordinated Universal Time (UTC) Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "T0930Z".


2 Answers

package main  import (     "time"     "fmt" )  func main(){     fmt.Println(time.Now().Format(time.RFC3339)) } 

golang Time.Format

like image 193
cikenerd Avatar answered Sep 30 '22 17:09

cikenerd


package main  import (     "fmt"     "time" )  func main() {     fmt.Println(time.Now().UTC().Format("2006-01-02T15:04:05-0700")) } 
like image 33
CrazyCrow Avatar answered Sep 30 '22 16:09

CrazyCrow