我如何在Golang中将RFC3339转换为UNIX

我如何在Golang中将RFC3339转换为UNIX

问题描述:

I want to show some RFC3339 time as seconds. I found how to parse times string, but it not that

t, _ := time.Parse(time.RFC3339, "2012-11-01T22:08:41+00:00") 

我想显示一些RFC3339时间,以秒为单位。 我发现了如何解析时间字符串,但不是这样 p>

  t,_:= time.Parse(time.RFC3339,“ 2012-11-01T22:08:41+  00:00“)
  code>  pre> 
  div>

For example,

package main

import (
    "fmt"
    "time"
)

func main() {
    t, err := time.Parse(time.RFC3339, "2012-11-01T22:08:41+00:00")
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(t)
    // Unix returns t as a Unix time,
    // the number of seconds elapsed since January 1, 1970 UTC.
    fmt.Println(t.Unix())
}

Playground: https://play.golang.org/p/LG6G4lMIWt

Output:

2012-11-01 22:08:41 +0000 UTC
1351807721