英文:
Can't parse date with golang, unexpected "e" string
问题
我正在尝试解析一个日期字符串 June, 24 2022
,
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Parse("Jan, 02 2006", "June, 24 2022"))
}
但是它失败了:
0001-01-01 00:00:00 +0000 UTC parsing time "June, 24 2022" as "Jan, 02 2006": cannot parse "e, 24 2022" as ", "
看起来 Golang 错误地将 "June" 解析为 "Jun",我该如何修复它?
英文:
I'm trying to parse a date string June, 24 2022
,
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Parse("Jan, 02 2006", "June, 24 2022"))
}
And it fails:
0001-01-01 00:00:00 +0000 UTC parsing time "June, 24 2022" as "Jan, 02 2006": cannot parse "e, 24 2022" as ", "
Looks like golang mistakenly took "June" as "Jun", how can I fix it?
答案1
得分: 3
如果你正在使用完整的月份名称,那么你的格式字符串应该使用"January",而不是"Jan"。
英文:
If you're using full month names, then your format string needs "January", not "Jan".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论