duanlu9970 2018-10-15 04:12
浏览 345
已采纳

GO时间字符串中的“ m = +”是什么? [重复]

This question already has an answer here:

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>
  • 写回答

1条回答 默认 最新

  • dth20986 2018-10-15 04:59
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Fluent udf 编写问题
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突