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
+10k Golang : Concatenate (combine) buffer data example
+12.1k Golang : Image to ASCII art example
+5.2k Linux/Unix : Commands that you need to be careful about
+14.1k Golang : How do I get the local IP (non-loopback) address ?
+8.1k Golang : How to check if a string with spaces in between is numeric?
+10.6k Golang : convert(cast) float to string
+28k Golang : missing Git command
+11k Golang : Encrypt and decrypt data with x509 crypto
+6.1k Golang : Squaring elements in array
+28.7k Get client IP Address in Go
+5.4k CodeIgniter : form input set_value cause " to become & quot
+16.4k How to enable MariaDB/MySQL logs ?