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
+6k Golang : Function as an argument type example
+7.3k Golang : Of hash table and hash map
+14.5k Golang : How to check if your program is running in a terminal
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+8.3k Swift : Convert (cast) Character to Integer?
+9.5k Golang : Convert(cast) string to int64
+28.6k Get file path of temporary file in Go
+8.9k Golang : Gaussian blur on image and camera video feed examples
+7k Web : How to see your website from different countries?
+13.1k Golang : List objects in AWS S3 bucket
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+6.5k Elasticsearch : Shutdown a local node