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
+6.7k Golang : md5 hash of a string
+45.8k Golang : Check if item is in slice/array
+2.3k Javascript : How to loop over and parse JSON data?
+4.3k Golang : Convert file content to Hex
+3.8k Golang : Another camera capture GUI application with GTK and OpenCV
+2.2k CloudFlare : Another way to get visitor's real IP address
+3.5k Golang : Emulate NumPy way of creating matrix example
+7.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+1.2k Golang : How to handle file size larger than available memory panic issue
+8.8k Golang : Date and Time formatting
+10.8k Golang : Convert Unix timestamp to UTC timestamp
+17.2k Golang : How to split or chunking a file to smaller pieces?