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
+13k Golang : Get checkbox or extract multipart form data value example
+6.5k Golang : Routes multiplexer routing example with regular expression control
+5.4k Golang : Null and nil value
+5.1k Linux : How to fix Brother HL-1110 printing blank page problem
+4.2k Linux : Disable and enable IPv4 forwarding
+9.4k Golang : Convert(cast) bigint to string
+6.5k Golang : Emulate NumPy way of creating matrix example
+16.2k Golang : Check if a directory exist or not
+5.3k Golang : Get expvar(export variables) to work with multiplexer
+13.3k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+34.6k Golang : Convert(cast) int64 to string
+9.3k Google Maps URL parameters configuration