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
+8.1k Golang : What fmt.Println() can do and println() cannot do
+8k Javascript : Put image into Chrome browser's console
+9.4k Golang : Temperatures conversion example
+5.8k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+9k Golang : Inject/embed Javascript before sending out to browser example
+7.5k Golang : Process json data with Jason package
+30k Golang : How to get HTTP request header information?
+6.1k Golang : Function as an argument type example
+22.4k Golang : Read directory content with filepath.Walk()
+20.3k Golang : How to get struct tag and use field name to retrieve data?
+9.8k Golang : List available AWS regions
+17.6k Golang : Linked list example