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
+11k Golang : Removes punctuation or defined delimiter from the user's input
+46.8k Golang : Marshal and unmarshal json.RawMessage struct example
+62.9k Golang : Convert HTTP Response body to string
+30.8k Golang : Remove characters from string example
+8.4k Golang : Number guessing game with user input verification example
+12.7k Golang : Forwarding a local port to a remote server example
+26.3k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+11.5k Golang : How to flush a channel before the end of program?
+18k Golang : Iterate linked list example
+9.7k Golang : Validate IPv6 example
+7.4k Golang : alternative to os.Exit() function
+6.2k Golang : Convert Chinese UTF8 characters to Pin Yin