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
+5.5k Golang : Combine slices of complex numbers and operation example
+4.6k Unix/Linux : How to find out the hard disk size?
+20.6k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+7.8k Golang : Get final balance from bit coin address example
+27.8k Golang : How to create new XML file ?
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+18.3k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+7.5k Golang : How to join strings?
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+5.7k Golang : Find the shortest line of text example
+23.7k Golang : Convert long hexadecimal with strconv.ParseUint example
+7.9k Golang : How to get username from email address