英文:
How to detect time in Go?
问题
我需要解析电子邮件头中的date_id字段。然而,这些电子邮件头的布局似乎略有不同,所以我已经开始构建一个switch case/block。我想知道这是否真的是解决这个问题的方法。
case strings.Contains(h.Headers[bk].Date, "(CEST)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
case strings.Contains(h.Headers[bk].Date, "(EDT)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
default:
layout = "Mon, 02 Jan 2006 15:04:05 -0700"
英文:
I need to parse the date_id field from emails headers. However these seem to have slightly different layouts so I've started to build a switch case/block . I'm wondering if that's really the way to fix this issue.
case strings.Contains(h.Headers[bk].Date, "(CEST)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
case strings.Contains(h.Headers[bk].Date, "(EDT)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
default:
layout = "Mon, 02 Jan 2006 15:04:05 -0700"
}
答案1
得分: 2
你可以使用mail.Header
并简单地调用.Date()
。
另一个选项是从line 70开始阅读代码并编写自己的函数。
英文:
You could use mail.Header
and simply call .Date()
on it.
Another option is to read the code starting from line 70 and write your own function.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论