now := time.Now() year, month, day := now.Date() //fmt.Println(year, month, day) //2021 September 1 fmt.Println(year, uint(month), day) //2021 9 1 //获取月份最后一天 lastTime := now.AddDate(0, 1, -1) lastYear, lastMonth, lastDay := lastTime.Date() fmt.Println(lastYear, int(lastMonth), lastDay) //2021 9 30