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.1k Golang : Transform lisp or spinal case to Pascal case example
+14k Golang : Fix image: unknown format error
+5.3k Golang *File points to a file or directory ?
+13.4k Android Studio : Password input and reveal password example
+18.6k Golang : convert int to string
+9.9k CodeIgniter : Load different view for mobile devices
+7.4k Golang : How to stop user from directly running an executable file?
+7.4k Golang : Dealing with struct's private part
+12.4k Golang : "https://" not allowed in import path
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+6k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+10.4k Swift : Convert (cast) String to Integer