8
Get year, month, day from time
source link: https://yourbasic.org/golang/day-month-year-from-time/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Get year, month, day from time
yourbasic.org/golang
The Date
function
returns the year, month and day of a time.Time
.
func (t Time) Date() (year int, month Month, day int)
In use:
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
The 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
)
Share:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK