如何解析这个日期2018-10-22T2250?

如何在 golang 中解析这个奇怪的日期时间 2018-10-22T2250?我找不到日期布局



MYYA
浏览 91回答 1
1回答

一只斗牛犬

您可以创建自己的自定义格式。在生产中,您还应该处理错误。package mainimport (    "fmt"    "time")func main() {    timeString := "2018-10-22T2250"    timeFormat := "2006-01-02T1504"    t, _ := time.Parse(timeFormat, timeString)    fmt.Println(t)}游乐场链接这将返回 UTC 时间。您可能需要调整到另一个时区,具体取决于您的来源。//init the locationloc, _ := time.LoadLocation("Asia/Shanghai")//localize the timelocalTime := t.In(loc)
打开App,查看更多内容
随时随地看视频慕课网APP