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
+40.5k Golang : Convert []byte to image
+24.6k Golang : missing Mercurial command
+39.1k Golang : How to count duplicate items in slice/array?
+4.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+4.4k PHP : Fix Call to undefined function curl_init() error
+3.7k Golang : How to pass data between controllers with JSON Web Token
+7.7k Golang : Gonum standard normal random numbers example
+16k Golang : How to make a file read only and set it to writable again?
+26.6k Golang : Change a file last modified date and time
+5.1k Golang : Missing Subversion command
+11.3k Golang : Covert map/slice/array to JSON or XML format