gpt4 book ai didi

go - 在 Go 中解析动态时间格式

转载 作者:数据小太阳 更新时间:2023-10-29 03:10:19 26 4
gpt4 key购买 nike

我正在使用一个外部 API,如果最后一个值为零,它有时会缩短返回的时间戳。

layout := "2006-01-02T15:04:05.000"
opened, err := time.Parse(layout, externallyFormattedTimestamp)
if err != nil {
fmt.Println("something went wrong parsing the timestamp")
fmt.Println(err.Error())
}

如果返回的 externallyFormattedTimestamp 是 2018-11-05T06:19:59.827,这将毫无问题地解析。

但如果返回的时间以零结尾,它将被缩短为 2018-11-05T06:19:59.8 而不是 2018-11-05T06:19:59.800,然后中断。我是否需要在解析之前手动将零附加到字符串,或者 Go 中是否有我遗漏的东西可以为我处理这个问题?

最佳答案

改为使用此布局:2006-01-02T15:04:05.999

关于go - 在 Go 中解析动态时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53149541/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com