doumo0206 2019-02-17 16:10
浏览 88
已采纳

时间戳中的“ m”是什么?如何在没有“ m”的情况下获得时间戳?

In Go , for time.Now() getting timestamp trailing with m=xx.xxxx..., what does that m means?

How to remove it while printing or Is there any other ways or function to get timestamp without m

For Example:- for time.Now() getting output => 2009-11-10 23:00:00 +0000 UTC m=+0.000000001

But i need output like this => 2009-11-10 23:00:00 +0000 UTC

  • 写回答

2条回答 默认 最新

  • duandian4501 2019-02-17 16:24
    关注

    i need output like this => 2009-11-10 23:00:00 +0000 UTC


    Package time

    import "time"

    Monotonic Clocks

    Operating systems provide both a “wall clock,” which is subject to changes for clock synchronization, and a “monotonic clock,” which is not. The general rule is that the wall clock is for telling time and the monotonic clock is for measuring time. Rather than split the API, in this package the Time returned by time.Now contains both a wall clock reading and a monotonic clock reading; later time-telling operations use the wall clock reading, but later time-measuring operations, specifically comparisons and subtractions, use the monotonic clock reading.

    The canonical way to strip a monotonic clock reading is to use t = t.Round(0).

    func (Time) Round 1.1

    func (t Time) Round(d Duration) Time
    

    Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.

    func (Time) String

    func (t Time) String() string
    

    String returns the time formatted using the format string

    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.


    The canonical way to strip a monotonic clock reading is to use t = t.Round(0).

    For example,

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        t := time.Now()
        fmt.Println(t)
        fmt.Println(t.Round(0))
    }
    

    Playground: https://play.golang.org/p/nglDbs9IGdU

    Output:

    2009-11-10 23:00:00 +0000 UTC m=+0.000000001
    2009-11-10 23:00:00 +0000 UTC
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题