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
+5.4k Javascript : Change page title to get viewer attention
+12.1k Golang : Convert decimal number(integer) to IPv4 address
+17.8k Golang : delete and modify XML file content
+6.2k Golang : Convert Chinese UTF8 characters to Pin Yin
+34.1k Golang : Call a function after some delay(time.Sleep and Tick)
+5.4k Golang : Print instead of building pyramids
+5.9k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+12.6k Elastic Search : Return all records (higher than default 10)
+9.9k Golang : Resumable upload to Google Drive(RESTful) example
+18.7k Golang : Set, Get and List environment variables
+9.1k Android Studio : Image button and button example
+4.5k Linux/MacOSX : Search and delete files by extension