Golang time.Time.UTC(), Unix() and UnixNano() functions example
package time
Golang time.Time.UTC(), Unix() and UnixNano() functions usage example.
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("Today : ", now.Format("Mon, Jan 2, 2006 at 3:04pm"))
utcTime := now.UTC()
fmt.Println("Today in UTC : ", utcTime)
unixTime := now.Unix()
fmt.Println("Today in Unix time : ", unixTime)
unixTimeNano := now.UnixNano()
fmt.Println("Nanosecond in Unix time : ", unixTimeNano)
// see also https://socketloop.com/tutorials/golang-convert-unix-timestamp-to-utc-timestamp
}
Sample output :
Today : Mon, Aug 10, 2015 at 12:31pm
Today in UTC : 2015-08-10 04:31:51.901152485 +0000 UTC
Today in Unix time : 1439181111
Nanosecond in Unix time : 1439181111901152485
References :
http://golang.org/pkg/time/#Time.UTC
Advertisement
Something interesting
Tutorials
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+17.6k Golang : Upload/Receive file progress indicator
+6.8k Swift : substringWithRange() function example
+6k Javascript : Get operating system and browser information
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+7.7k Golang : get the current working directory of a running program
+18.8k Golang : Delete duplicate items from a slice/array
+6k Golang : Function as an argument type example
+52.6k Golang : How to get struct field and value by name
+10.1k Golang : Check a web page existence with HEAD request example
+9.1k Golang : Handle sub domain with Gin