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
+8.7k Golang : Another camera capture GUI application with GTK and OpenCV
+4.9k Facebook : How to place save to Facebook button on your website
+21.6k Curl usage examples with Golang
+8.3k Golang : Check from web if Go application is running or not
+6.3k Golang & Javascript : How to save cropped image to file on server
+13.6k Golang : Get constant name from value
+8.1k Golang : Handle Palindrome string with case sensitivity and unicode
+8.9k Golang : Random integer with rand.Seed() within a given range
+7k Mac/Linux/Windows : Get CPU information from command line
+21k Golang : Underscore or snake_case to camel case example
+12.1k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+14.1k Golang : concatenate(combine) strings