Go: Get year, month, day from time
returns the year, month and day of a
func (t Time) Date() (year int, month Month, day int)
year, month, day := time.Now().Date() fmt.Println(year, month, day) // For example 2009 November 10 fmt.Println(year, int(month), day) // For example 2009 11 10
You can also extract the information with seperate calls:
t := time.Now() year := t.Year() // type int month := t.Month() // type time.Month day := t.Day() // type int
time.Month type specifies a month of the year (January = 1, …).
type Month int const ( January Month = 1 + iota February March April May June July August September October November December )
Be the first to comment!