go - GO 时间字符串中的 "m=+"是什么?

标签 go time

<分区>

我正在试验 Google OAuth2,我在刷新 token 到期时遇到了这个问题。它来自 2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401

我知道这是一种时间格式,但我无法在任何地方找到有关 m=+ 的任何信息。它是谷歌内部使用的吗?我尝试用 time.RFC3339 解析它,但正如您猜到的那样,它忽略了 m=+。它说

parsing time "2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401" as "2006-01-02T15:04:05Z07:00": cannot parse " 15:42:37.5989253 +1100 AEDT m=+3610.688917401" as "T"

那么时间字符串中的m=+是什么?

最佳答案

m=±<value>monotonic clock秒读。

来自 time.Time.String documentation 的解释:

If the time has a monotonic clock reading, the returned string includes a final field "m=±", where value is the monotonic clock reading formatted as a decimal number of seconds.

Afaik,golang 不提供解析单调时钟的布局,所以在我看来删除它是安全的。

dateFormat := "2006-01-02 15:04:05.999999999 -0700 MST"
dateString := "2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401"

t, err := time.Parse(dateFormat, strings.Split(dateString, " m=")[0])
if err != nil {
    fmt.Println(err)
    os.Exit(0)
}

fmt.Println(t) // 2018-10-15 15:42:37.5989253 +1100 AEDT

go 1.9开始, 调用 .String()将生成带有单调时钟的日期字符串输出。所以我建议尝试使用 .Format()用于正常使用而不是 .String() .

单调时钟信息仅对调试有用。

关于go - GO 时间字符串中的 "m=+"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52809661/

相关文章:

go - 如何限制 Golang 中变量的值?

json - 解码格式不正确的日期时间

session - 如何检测 session 是否即将过期?

python - matplotlib 中的 100% 堆积面积/直方图,X 轴上有日期

来自 millis 的 Java Date - long 与 int

go - Makefile 规则始终执行,尽管目标存在

go - ANTLR4内存使用情况

Python Pandas : Convert Minutes to Datetime

ios - 使用非公历创建 UNNotification

python - 在 Python 中将当前时间提前一小时