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
+5.8k CloudFlare : Another way to get visitor's real IP address
+5.3k Golang : Extract sub-strings
+5.9k Golang : How to call function inside template with template.FuncMap
+9.9k Golang : Intercept and process UNIX signals example
+28k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+7.2k How to show different content from website server when AdBlock is detected?
+8.8k Golang : Function wrapper that takes arguments and return result example
+5.8k Restart Apache or Nginx web server without password prompt
+7.6k Golang : Convert(cast) []byte to io.Reader type
+8k Golang : Inject/embed Javascript before sending out to browser example
+17.2k Golang : Generate thumbnails from images
+8.6k Golang : Eroding and dilating image with OpenCV example