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
+9.9k Golang : Roll the dice example
+10.8k Golang : Verify Linux user password again before executing a program example
+7.2k Golang : Multiplexer with net/http and map
+16.5k Golang : How to make a file read only and set it to writable again?
+18.7k Golang : Archive directory with tar and gzip
+5.3k Java : Human readable password generator
+21.1k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+14.1k nginx: [emerg] unknown directive "ssl"
+13.4k Golang : Recombine chunked files example
+8k Golang : Simple histogram example
+5.6k Golang : Experimental emojis or emoticons icons programming language
+25k Mac/Linux and Golang : Fix bind: address already in use error