GO时间字符串中的“ m = +”是什么? [重复]
This question already has an answer here:
- Unexpected output from time.Time 3 answers
I'm experimenting with Google OAuth2 and I encountered this in the expiry time of my refresh token. It comes from 2018-10-15 15:42:37.5989253 +1100 AEDT m=+3610.688917401
I know it's a time format but I couldn't find any information about m=+
anywhere. Is it used internally by Google? I tried to parse it with time.RFC3339
but as you can guess, it ignores the m=+
. It says
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"
So what's this m=+
in the time string?
</div>
此问题已经存在 在这里有答案: p>
-
来自时间的意外输出。时间
3个答案
span>
ul>
div>
我正在尝试使用Google OAuth2,并且在刷新令牌的有效期内遇到了此问题。 它来自
2018-10-15 15:42:37.5989253 +1100 AEDT m = + 3610.688917401 code> p>
我知道这是一种时间格式,但我找不到 任何地方有关
m = + code>的任何信息。 Google内部使用它吗? 我尝试使用
time.RFC3339 code>解析它,但是您可以猜到,它忽略了
m = + code>。 p>
将解析时间“ 2018-10-15 15:42:37.5989253 +1100 AEDT m = + 3610.688917401”表示为“ 2006-01-02T15:04: 05Z07:00“:无法将” 15:42:37.5989253 +1100 AEDT m = + 3610.688917401“解析为” T“ p> blockquote>
这是什么
时间字符串中的m = + code>? p> div>
The m=±<value>
is monotonic clock reading in second.
Below is an explanation from time.Time.String
documentation about that:
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 doesn't provide layout for parsing monotonic clock, so in my opinion it's safe to remove it.
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
Starting from go 1.9, calling .String()
will generates date string output with monotonic clock in it. So I suggest try to use .Format()
for normal usage instead of .String()
. The monotonic clock info only useful for debugging purpose.