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
+8.4k Golang : Quadratic example
+9.4k Golang : Underscore string example
+9.2k Golang : How to get quoted string into another string?
+16.5k Golang : Put UTF8 text on OpenCV video capture image frame
+14.3k Golang : invalid character ',' looking for beginning of value
+11.2k Golang : How to check if a string starts or ends with certain characters or words?
+7.2k Golang : Routes multiplexer routing example with regular expression control
+13.5k Golang : Save(pipe) HTTP response into a file
+6.5k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+16k Golang : How to save log messages to file?
+8.8k Golang : Test a slice of integers for odd and even numbers
+14.8k Golang : Delete files by extension