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
+16.4k Golang : Convert slice to array
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+28.5k Golang : Change a file last modified date and time
+30.4k Golang : How to redirect to new page with net/http?
+6.4k CodeIgniter : form input set_value cause " to become & quot
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+18.4k Golang : Read binary file into memory
+5.8k Linux : Disable and enable IPv4 forwarding
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+15.8k Golang : Get digits from integer before and after given position example
+22.2k Golang : Match strings by wildcard patterns with filepath.Match() function