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
+6k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+9.1k Golang : Temperatures conversion example
+6.7k Nginx : Password protect a directory/folder
+24.2k Golang : GORM read from database example
+6.8k Golang : How to call function inside template with template.FuncMap
+6.8k Golang : Gargish-English language translator
+8.2k Golang : Ackermann function example
+11.8k Golang : Sort and reverse sort a slice of runes
+9.8k Golang : Get escape characters \u form from unicode characters
+5.9k Java : Human readable password generator
+7.9k How to show different content from website server when AdBlock is detected?
+4.7k Javascript : How to get width and height of a div?