What is the "m" in timestamp and how to get timestamp without "m"?

Issue

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

Solution

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

Answered By – peterSO

Answer Checked By – Jay B. (GoLangFix Admin)

Leave a Reply

Your email address will not be published.