Golang : How to get time from unix nano example
Just an add on to previous tutorial on how to get time in milliseconds. This is a short tutorial on how to convert UnixNano()
nanoseconds to UTC time.
Here you go!
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
nano := now.UnixNano()
fmt.Println("Today : ", now)
fmt.Println("Today's unix nano is : ", nano)
UTCfromUnixNano := time.Unix(0, nano)
fmt.Println("Today from Unix Nano : ", UTCfromUnixNano)
}
Sample output :
Today : 2015-08-17 13:32:31.045120419 +0800 MYT
Today's unix nano is : 1439789551045120419
Today from Unix Nano : 2015-08-17 13:32:31.045120419 +0800 MYT
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+16.1k Golang : Iterate linked list example
+31.2k Golang : How to check if a date is within certain range?
+9.3k Golang : Meaning of omitempty in struct's field tag
+9.1k Golang : Text file editor (accept input from screen and save to file)
+17.8k Golang : Fix cannot download, $GOPATH not set error
+10k Google Maps URL parameters configuration
+11.4k Golang : "https://" not allowed in import path
+4.2k Golang : Get FX sentiment from website example
+19.1k Golang : How to force compile or remove object files first before rebuild?
+8.8k Golang : Translate language with language package example
+8.1k Golang : How to check if a string with spaces in between is numeric?
+10k Golang : Concatenate (combine) buffer data example