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.8k Golang : Shortening import identifier
+6.1k Linux/MacOSX : Search for files by filename and extension with find command
+11.3k Golang : Roll the dice example
+8.6k Your page has meta tags in the body instead of the head
+5.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+5.9k Golang : Markov chains to predict probability of next state example
+12.9k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+16.9k Golang : Gzip file example
+11k Golang : Natural string sorting example
+8.9k Golang : How to join strings?
+8.7k Golang : How to check variable or object type during runtime?
+14k Golang : Qt progress dialog example