如何在Go中检测时间?

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

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.

huangapple
  • 本文由 发表于 2014年7月31日 18:10:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/25056227.html
匿名

发表评论

匿名网友

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

确定