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
+15.2k Golang : Find location by IP address and display with Google Map
+11k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+8.9k Golang : How to use Gorilla webtoolkit context package properly
+6.4k Elasticsearch : Shutdown a local node
+5.5k Unix/Linux : How to find out the hard disk size?
+20k Golang : Check if os.Stdin input data is piped or from terminal
+13k Golang : How to calculate the distance between two coordinates using Haversine formula
+6.8k Golang : Fibonacci number generator examples
+4.4k Java : Generate multiplication table example
+30.2k Golang : How to redirect to new page with net/http?
+34.4k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+6.6k Golang : Experimental emojis or emoticons icons programming language