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
+6.7k Golang : Grayscale Image
+10.1k CodeIgniter : How to check if a session exist in PHP?
+12k Golang : Image to ASCII art example
+9k Android Studio : Simple input textbox and intercept key example
+16.4k Golang : Upload/Receive file progress indicator
+3.6k Linux/MacOSX : Search and delete files by extension
+8.2k Golang : Extract or copy items from map based on value
+19.4k Golang : Convert PNG transparent background image to JPG or JPEG image
+22.8k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+14.2k Golang : Get checkbox or extract multipart form data value example
+7.5k Golang : How to capture return values from goroutines?
+5.8k Fix sudo yum hang problem with no output or error messages