请像我2018-12-17 12:55:50 +0300在golang中帮助我解析日期
2018-12-17 12:55:50 +0300
我正在尝试布局
layout := "2006-01-02 15:04:05 +0000" dateString := "2018-12-17 12:55:50 +0300" t, err := time.Parse(layout, dateString) if err != nil { fmt.Println("Error while parsing date :", err) } fmt.Println(t.Format("2006-01-02 15:04:05"))
但是编译器说 Error while parsing date : parsing time "2018-12-17 12:55:50 +0300" as "2006-01-02 15:04:05 +0000": cannot parse "300" as " +0000"
Error while parsing date : parsing time "2018-12-17 12:55:50 +0300" as "2006-01-02 15:04:05 +0000": cannot parse "300" as " +0000"
包装时间 导入“时间” [布局]参考时间可以认为是 01/02 03:04:05PM '06 -0700
包装时间
导入“时间”
[布局]参考时间可以认为是
01/02 03:04:05PM '06 -0700
使用-0700,而不是+0000。
-0700
+0000
例如,
package main import ( "fmt" "time" ) func main() { layout := "2006-01-02 15:04:05 -0700" dateString := "2018-12-17 12:55:50 +0300" t, err := time.Parse(layout, dateString) if err != nil { fmt.Println("Error while parsing date :", err) } fmt.Println(t.Format("2006-01-02 15:04:05")) }
游乐场:https : //play.golang.org/p/Xr8zaTjODgC
输出:
2018-12-17 12:55:50