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
+17.9k Golang : How to remove certain lines from a file
+15.7k Golang : Generate universally unique identifier(UUID) example
+4.4k Javascript : Access JSON data example
+5.1k Javascript : How to loop over and parse JSON data?
+14.3k Golang : Execute function at intervals or after some delay
+27.8k Golang : Connect to database (MySQL/MariaDB) server
+7k Golang : How to fix html/template : "somefile" is undefined error?
+6.5k Golang : Reverse by word
+7.6k Javascript : How to check a browser's Do Not Track status?
+8.2k Golang : How to check if input string is a word?
+13.7k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+7.3k Golang : Rename part of filename