Answers for "Golang convert from ISO 8601 to milliseconds"

Go
0

Golang convert from ISO 8601 to milliseconds

func main() {
  // convert iso-8601 into rfc-3339 format
  rfc3339t := strings.Replace("2015-12-23 00:00:00", " ", "T", 1) + "Z"

  // parse rfc-3339 datetime
  t, err := time.Parse(time.RFC3339, rfc3339t)
  if err != nil {
    panic(err)
  }

  // convert into unix time
  ut := t.UnixNano() / int64(time.Millisecond)

  fmt.Println(ut)
}
Posted by: Guest on August-04-2020

Browse Popular Code Answers by Language