Golang : Get current, epoch time and display by year, month and day
Problem :
You need to get current and Epoch(Unix) time and display the time by year, month and day.
Solution :
Use the http://golang.org/pkg/time functions to get current and epoch time. There are methods to break the time down to year, month, day, hour and minutes as well.
For example :
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
epoch := now.Unix()
fmt.Println("Now: ", now)
fmt.Println("Epoch(Unix) Time: ", epoch)
fmt.Println(now.Format("Mon, Jan 2, 2006 at 3:04pm"))
fmt.Println("Day: ", now.Day())
fmt.Println("Month: ", now.Month())
fmt.Println("Year: ", now.Year())
fmt.Println("Hour: ", now.Hour())
fmt.Println("Minute: ", now.Minute())
}
Reference :
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
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+14.3k Golang : Simple word wrap or line breaking example
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+5.9k Golang : Denco multiplexer example
+14.5k Golang : How to determine if user agent is a mobile device example
+12.6k Golang : Transform comma separated string to slice example
+35.1k Golang : Upload and download file to/from AWS S3
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+13.6k Golang : reCAPTCHA example
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+9.4k Golang : Find the length of big.Int variable example
+11.7k Golang : Gorilla web tool kit secure cookie example