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
+5.7k Golang : Check from web if Go application is running or not
+34.4k Golang : Convert(cast) int64 to string
+9.6k Golang : Remove or trim extra comma from CSV
+21.8k Golang : Convert uint value to string type
+15.5k Golang : Generate thumbnails from images
+7.7k Golang : Convert(cast) string to int64
+14k Golang : Convert slice to array
+22.2k Golang : dial tcp: too many colons in address
+4.2k Fontello : How to load and use fonts?
+6.3k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+3.9k Golang : How to solve "too many .rsrc sections" error?