Parsing date string in Go

前端 未结 7 2096
小蘑菇
小蘑菇 2020-11-22 15:18

I tried parsing the date string \"2014-09-12T11:45:26.371Z\" in Go.

Code

layout := \"2014-09-12T11:45:26.371Z\"
str :=         


        
7条回答
  •  我在风中等你
    2020-11-22 15:58

    As answered but to save typing out "2006-01-02T15:04:05.000Z" for the layout, you could use the package's constant RFC3339.

    str := "2014-11-12T11:45:26.371Z"
    t, err := time.Parse(time.RFC3339, str)
    
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(t)
    

    https://play.golang.org/p/Dgu2ZvHwTh

提交回复
热议问题