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
+21.2k Golang : Round float to precision example
+6k Golang : Accessing dataframe-go element by row, column and name example
+13.4k Golang : package is not in GOROOT during compilation
+11.3k Elastic Search : Return all records (higher than default 10)
+6.3k Golang : Scanf function weird error in Windows
+17.7k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+12k Golang : Date and Time formatting
+31.6k Delete a directory in Go
+8.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+13.2k Golang : How to shuffle elements in array or slice?
+15.2k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+32.4k Golang : How to check if slice or array is empty?