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
+7.3k Golang : Convert(cast) io.Reader type to string
+13.9k Golang : Chunk split or divide a string into smaller chunk example
+9.9k Golang : How to tokenize source code with text/scanner package?
+12.3k Golang : Transform comma separated string to slice example
+16.8k Golang : Find file size(disk usage) with filepath.Walk
+22.6k Golang : Test file read write permission example
+6.4k Golang : Skip or discard items of non-interest when iterating example
+6.9k Golang : How to fix html/template : "somefile" is undefined error?
+8.5k Golang : Find duplicate files with filepath.Walk
+8.2k Golang : How to check variable or object type during runtime?
+18.2k Golang : Example for RSA package functions
+9.7k Golang : Setting variable value with ldflags