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
+15.3k Golang : Get checkbox or extract multipart form data value example
+15.6k Golang : Read a file line by line
+31.1k Golang : How to convert(cast) string to IP address?
+8.7k Golang : Get SPF and DMARC from email headers to fight spam
+17.4k Golang : Qt image viewer example
+11k Golang : How to use if, eq and print properly in html template
+10.1k Android Studio : Simple input textbox and intercept key example
+8.5k Golang : Heap sort example
+6.9k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+13.4k Golang : Tutorial on loading GOB and PEM files
+9.4k Golang : Eroding and dilating image with OpenCV example
+11.7k Golang : Convert a rune to unicode style string \u