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
+9.2k Golang : How to protect your source code from client, hosting company or hacker?
+13.8k Golang : Google Drive API upload and rename example
+6.5k Golang : Skip or discard items of non-interest when iterating example
+6.7k Golang : Normalize email to prevent multiple signups example
+15k Golang : Accurate and reliable decimal calculations
+9.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+7.1k Linux : How to fix Brother HL-1110 printing blank page problem
+10.6k Golang : Removes punctuation or defined delimiter from the user's input
+13k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+9k Golang : Create and shuffle deck of cards example
+10.3k Golang : Select region of interest with mouse click and crop from image
+52.1k Golang : How to get struct field and value by name