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
+7.6k Golang : How to handle file size larger than available memory panic issue
+21.7k Golang : GORM create record or insert new record into database example
+8.1k Golang : Get all countries phone codes
+18.5k Golang : Write file with io.WriteString
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+26.7k Golang : How to check if a connection to database is still alive ?
+13.9k Golang : Get current time
+9.4k Golang : Play .WAV file from command line
+10k Golang : Translate language with language package example
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+5k JQuery : Calling a function inside Jquery(document) block