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
+8.1k Golang : Implementing class(object-oriented programming style)
+32.4k Golang : Regular Expression for alphanumeric and underscore
+14.5k Golang : Normalize unicode strings for comparison purpose
+10.7k Golang : How to transmit update file to client by HTTP request example
+20.2k Golang : Secure(TLS) connection between server and client
+10.3k Golang : Select region of interest with mouse click and crop from image
+8.8k Golang : How to capture return values from goroutines?
+6.9k Golang : Transform lisp or spinal case to Pascal case example
+7.2k Golang : Rot13 and Rot5 algorithms example
+9k Golang : Generate EAN barcode
+10.3k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+7.5k Golang : Trim everything onward after a word