这是一个示例,我想解析的数据中的日期如何:
2017-10-20 13:32:26,890
我的格式如下:
2006-01-02 15:04:05,000
现在奇怪的部分:
date := "2017-10-20 13:32:26,890"
_, err := time.Parse("2006-01-02 15:04:05,000", date)
if err != nil {
panic(err)
}
如果我运行此命令,我会收到此错误:
panic: parsing time "2017-10-20 13:32:26,890" as "2006-01-02 15:04:05,000": cannot parse "890" as ",000"
如果我将日期和格式中的逗号更改为单个点,它就可以正常工作。我可以用正则表达式替换逗号,但为什么会发生这种情况?
最佳答案
此问题已通过 f02a26be
[1] (2021-03-15) 修复。引用新文档 [2]:
Either a comma or decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed.
关于date - 如果有逗号,Golang 无法解析毫秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47096450/