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.8k Golang : Getting Echo framework StartAutoTLS to work
+8.2k Golang : Add build version and other information in executables
+13.9k Golang : Human readable time elapsed format such as 5 days ago
+15.9k Golang : Read a file line by line
+26k Mac/Linux and Golang : Fix bind: address already in use error
+15.4k Golang : invalid character ',' looking for beginning of value
+8.9k Golang : Populate or initialize struct with values example
+12.1k Golang : Save webcamera frames to video file
+19.6k Golang : Get current URL example
+18.5k Golang : Aligning strings to right, left and center with fill example
+9.8k Golang : Get current, epoch time and display by year, month and day
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content