英文:
GO: Date and Time Parsing in GO
问题
我有一个格式化字符串"day/month/year, hour:minute:second",我该如何解析成时间对象?
我尝试了以下代码:
const longForm = "5/01/2015, 12:00:00"
t1, _ := time.Parse(longForm, "5/01/2015, 12:00:00")
但是我得到了一些UTC时间,但这对于比较时间并不有用,因为它们都得到了相同的UTC时间。有什么帮助吗?
英文:
I have format string "day/month/year, hour:minute:second"
How do I parse into a time object?
I tried:
const longForm = "5/01/2015, 12:00:00"
t1, _ := time.Parse(longForm, "5/01/2015, 12:00:00")
0001-01-01 00:00:00 +0000 UTC
I get some UTC time, but this is not helpful if I want to compare times because I get the same UTC time for them all. Any help?
答案1
得分: 3
规则 #1 的战斗俱乐部,呃,检查你的错误。
话虽如此,时间解析的格式在文档中有定义(向下滚动到常量部分)。
对于你的具体问题,格式是 1/_2/2006, 15:04:05
。
英文:
Rule #1 of fightclub, err Go, check your errors.
That being said, the format for time parsing is defined in the documentation (scroll down to constants).
For your specific question, the format is 1/_2/2006, 15:04:05
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论