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
+13.3k Generate salted password with OpenSSL example
+5.9k Golang : Debug with Godebug
+8.4k Golang : Convert(cast) []byte to io.Reader type
+16.2k Golang : Send email and SMTP configuration example
+11.7k Golang : Determine if time variables have same calendar day
+9.2k Golang : Create unique title slugs example
+14.8k Golang : How to check if IP address is in range
+14.2k Golang : How to determine if user agent is a mobile device example
+10.9k Golang : Intercept and process UNIX signals example
+15.2k Golang : Force download file example
+6.7k Golang : Decode XML data from RSS feed
+31.2k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions