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
+11.9k Golang : Split strings into command line arguments
+10.6k Golang : Sieve of Eratosthenes algorithm
+86k Golang : How to convert character to ASCII and back
+6.9k Golang : Array mapping with Interface
+15.2k Golang : Force download file example
+16.1k CodeIgniter/PHP : Create directory if does not exist example
+7.5k Golang : Test if an input is an Armstrong number example
+13.2k Facebook PHP getUser() returns 0
+7.9k Golang : Add build version and other information in executables
+13.2k Golang : Get user input until a command or receive a word to stop
+13.3k Generate salted password with OpenSSL example
+11.9k Golang : List running EC2 instances and descriptions