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
+14.4k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+30.6k Golang : Validate email address with regular expression
+8.9k Golang : Setting variable value with ldflags
+15.7k Golang : How to tell if a file is compressed either gzip or zip ?
+7.9k Golang : Find the length of big.Int variable example
+18.2k Golang : Measure http.Get() execution time
+17.4k Golang : Check whether a network interface is up on your machine
+14.2k Golang : How to add color to string?
+22.8k Golang : Daemonizing a simple web server process example
+11.6k Golang : Transform comma separated string to slice example
+9.9k Android Studio : Create custom icons for your application example
+13.4k Golang : Submit web forms without browser by http.PostForm example