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
+20.5k Golang : Create and resolve(read) symbolic links
+27.7k Golang : Change a file last modified date and time
+47.9k Golang : Upload file from web browser to server
+5.3k Golang : Error handling methods
+9.8k Golang : Embed secret text string into binary(executable) file
+7.5k Golang : Grayscale Image
+42.3k Golang : Get hardware information such as disk, memory and CPU usage
+5.8k Golang : Calculate US Dollar Index (DXY)
+84.6k Golang : How to convert character to ASCII and back
+15.5k Golang : Generate universally unique identifier(UUID) example
+11.6k Golang : How to parse plain email text and process email header?
+11.5k Golang : flag provided but not defined error