无法使用golang解析日期,出现意外的”e”字符串。

huangapple go评论83阅读模式
英文:

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".

huangapple
  • 本文由 发表于 2022年6月28日 13:20:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/72781078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定