什么是"m"?时间戳,以及如何在没有"m"的情况下获取时间戳? [英] What is the "m" in timestamp and how to get timestamp without "m"?

查看:168
本文介绍了什么是"m"?时间戳,以及如何在没有"m"的情况下获取时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Go中,获取time.Now()以 m = xx.xxxx ... 跟踪时间戳, m 是什么意思?

如何在打印时将其删除,或者是否有其他方法或功能可以在没有 m

的情况下获得时间戳记

例如:-for time.Now()获取输出=> 2009-11-10 23:00:00 +0000 UTC m = + 0.000000001

但是我需要这样的输出=> 2009-11-10 23:00:00 +0000 UTC

解决方案

我需要这样的输出=> 2009-11-10 23:00:00 +0000 UTC


打包时间

导入时间"

单调时钟

操作系统同时提供挂钟",这取决于 更改时钟同步和单调时钟",即 不是.一般规则是,挂钟用于告知时间, 单调时钟用于测量时间.与其拆分API, 在这个包中,time返回的是time. 时钟读数和单调时钟读数;以后讲故事 操作使用挂钟读数,但稍后要进行时间测量 运算,特别是比较和减法,请使用 单调时钟读取.

剥离单调时钟读数的典型方法是使用t = t.Round(0).

功能(时间)回合 1.1

func (t Time) Round(d Duration) Time

Round返回将t舍入到d的最接近倍数的结果 (自零时间开始).中途值的舍入行为是 围捕.如果d <= 0,则Round返回去除了任何单调时钟的t 阅读,但其他方面不变.

func(时间)字符串

func (t Time) String() string

字符串返回使用格式字符串格式化的时间

如果时间具有单调时钟读数,则返回字符串 包括最后一个字段"m =±",其中值是单调的 时钟读数格式为秒的十进制数.


剥离单调时钟读数的典型方法是使用 t = t.Round(0).

例如,

package main

import (
    "fmt"
    "time"
)

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

游乐场: https://play.golang.org/p/nglDbs9IGdU

输出:

2009-11-10 23:00:00 +0000 UTC m=+0.000000001
2009-11-10 23:00:00 +0000 UTC

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

解决方案

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

这篇关于什么是"m"?时间戳,以及如何在没有"m"的情况下获取时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆