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

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 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数