【发布时间】:2020-08-14 10:24:45
【问题描述】:
我正在尝试使用自定义格式解析日期 - ddmmmyyyy。例如:
15may1997
dd 15
mmm may
yyyy 1997
这是我的代码:
const customFormat = "02jan2006"
t, err := time.Parse(customFormat, "15may1997")
if err != nil {
fmt.Println(err)
}
这是输出:
parsing time "15may1997" as "02jan2006": cannot parse "may1997" as "jan"
只有换天才能解析成功:
t, err := time.Parse(customFormat, "15jan2006")
我尝试阅读 this 和 this 以及更多文章,但不知道如何自定义我的格式。
我在这里做错了什么?
谢谢。
【问题讨论】:
-
“可识别的星期格式为“Mon”和“Monday”。可识别的月份格式为“Jan”和“January”。” 即使用
Jan而不是jan。 play.golang.com/p/ndO8Vf1MkIQ -
你是绝对正确的 :) 谢谢 mkoprita