Golang : How to get year, month and day?
Problem :
You want to extract the year, month and day from today's date. How to do that?
Solution :
Use the time.Now().Date()
function to get year, month and day from today's date.
For example :
package main
import (
"fmt"
"time"
)
func main() {
year, month, day := time.Now().Date()
fmt.Println("Year : ", year)
fmt.Println("Month : ", month)
fmt.Println("Day : ", day)
if month == time.November && day == 10 {
fmt.Println("Happy Go day!")
}
}
Sample output :
Year : 2015
Month : August
Day : 3
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
+3.3k Javascript : How to show different content with noscript?
+4.1k Golang : How to deal with configuration data?
+5.8k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+18.7k Golang : Saving private and public key to files
+33k Golang : How to split or chunking a file to smaller pieces?
+15.6k Golang : Clone with pointer and modify value
+4.7k Golang : Shuffle array of list
+21.8k Golang : Print out struct values in string format
+19.1k Golang : Convert string slice to struct and access with reflect example
+8k Golang : ffmpeg with os/exec.Command() returns non-zero status
+10.1k Golang : Convert(cast) bigint to string
+17.8k Mac OSX : Homebrew and Golang