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
+22.7k Golang : Upload to S3 with official aws-sdk-go package
+7k Golang : Load DSA public key from file example
+30.2k Golang : Math pow(the power of x^y) example
+25.8k Golang : Convert CSV data to JSON format and save to file
+8.7k Golang : Resumable upload to Google Drive(RESTful) example
+17.9k Golang : Fix cannot download, $GOPATH not set error
+4.6k PHP : Convert CSV to JSON with YQL example
+16.6k Golang : Put UTF8 text on OpenCV video capture image frame
+7.1k Golang : Qt splash screen with delay example
+10.1k How to test Facebook App on localhost ?
+10.7k Golang : convert(cast) float to string
+7.5k PHP : How to parse ElasticSearch JSON ?