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
+4.9k Fix yum-complete-transaction error
+12k Python : Convert IPv6 address to decimal and back to IPv6
+3.7k Javascript : How to show different content with noscript?
+5k Unix/Linux : Get reboot history or check when was the last reboot date
+11.5k Golang : Listen and Serve on sub domain example
+5.2k PHP : How to check if an array is empty ?
+4.1k Nginx and PageSpeed build from source CentOS example
+10.4k CodeIgniter : How to check if a session exist in PHP?
+9.6k Golang : ISO8601 Duration Parser example
+3.7k Golang : Valued expressions and functions example
+34.3k Golang : Save image to PNG, JPEG or GIF format.
+5.4k Golang : Build new URL for named or registered route with Gorilla webtoolkit example