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
+43.3k Golang : Marshal and unmarshal json.RawMessage struct example
+25.9k Golang : Move file to another directory
+29k Golang : Convert an image file to []byte
+5.6k Golang : How to call function inside template with template.FuncMap
+13k Golang : Accurate and reliable decimal calculations
+7.4k Golang : How to get username from email address
+4.6k Unix/Linux : Get reboot history or check when was the last reboot date
+3.2k Javascript : Detect when console is activated and do something about it
+12.2k Golang : convert rune to unicode hexadecimal value and back to rune character
+6.2k Golang : How to convert strange string to JSON with json.MarshalIndent
+7.8k Golang : Timeout example
+17k Golang : How to get own program name during runtime ?