小编sie*_*sta的帖子

time.Parse行为

在Go中,在尝试将字符串转换time.Time为时,使用时间包的Parse方法不会返回预期结果.似乎问题在于时区.我想更改为ISO 8601以及UTC中的日期和时间.

package main

import (
    "fmt"
    "time"
)

func main() {
    const longForm = "2013-05-13T18:41:34.848Z"
    //even this is not working
    //const longForm = "2013-05-13 18:41:34.848 -0700 PDT"
    t, _ := time.Parse(longForm, "2013-05-13 18:41:34.848 -0700 PDT")
    fmt.Println(t)
    //outputs 0001-01-01 00:00:00 +0000 UTC
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

time timezone datetime parsing go

0
推荐指数
1
解决办法
722
查看次数

标签 统计

datetime ×1

go ×1

parsing ×1

time ×1

timezone ×1