Learn about Program to get the date, month, year using Date() function in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Program to get the date, month, year using Date() function in Golang
// Golang program to get current date
// using Date() function
package main
import "fmt"
import "time"
func main() {
YYYY, MM, DD := time.Now().Date()
fmt.Println("Date : ", DD)
fmt.Println("Month: ", MM)
fmt.Println("Year : ", YYYY)
}
Here, we called time.Now().Date() function to get current date. The Date() function returns the date, month, year. Then we assigned the result in YYYY, MM, DD variables
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Program to print current date-time using Format() function in Golang
Program to get current date and time in Golang