Golang’s Time package: second, millisecond, nanosecond timestamp output

Time stamp classification

A 10-digit timestamp is in seconds;

The 13-digit timestamp is in milliseconds;

19-digit timestamps are in nanoseconds;

In Golang:

package main

import (
"time"
"fmt"
)

func main() {
Fmt.printf (" Timestamp (s) : %v; \n", time.Now().Unix())
Fmt. Printf(" timestamp (nanosecond) : %v; \n",time.Now().UnixNano())
Fmt.printf (" timestamp (ms) : %v; \n",time.Now().UnixNano() / 1e6)
Fmt. Printf(" timestamp (nanoseconds converted to seconds) : %v; \n",time.Now().UnixNano() / 1e9)
}

Timestamp (s) : 1634183046;

Time stamp (nanosecond) : 1634183046062029000;

Timestamp (ms) : 1634183046062;

Timestamp (nanoseconds converted to seconds) : 1634183046;

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish