问题描述
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"
01/02 03:04:05PM '06 -0700
-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"))
}
输出:
2018-12-17 12:55:50
2018-12-17 12:55:50 +0300
I'm trying with layout
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"
01/02 03:04:05PM '06 -0700
-0700+0000
For example,
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"))
}
Output:
2018-12-17 12:55:50
这篇关于在golang中解析日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!