go语言内置time模块
improt (\"time\"\"fmt\")func main() {now := time.Now()week := now.Weekday()offset := int(time.Monday-week)if offset > 0 {offset = -6}fmt.Println(offset)//周StartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)EndDates := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, time.Local)fmt.Println(\"周一\",StartDate.AddDate(0, 0, offset))//周一fmt.Println(\"周末\",EndDates.AddDate(0, 0,int((week+1)-week)))//周末//月currentYear,currentMonth,_ := now.Date()currentLocation := now.Location()firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, currentLocation)//月初开始EndOfMonth := time.Date(now.Year(), now.Month(), 1, 23, 59, 59, 999999999, currentLocation)//月初开始lastOfMonth := EndOfMonth.AddDate(0, 1, -1)//月底结束fmt.Println(\"月初\",firstOfMonth)fmt.Println(\"月末\",lastOfMonth)//今天firstOfDay := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)//今天开始lastOfDay := time.Date(currentYear, currentMonth, 1, 23, 59, 59, 999999999, currentLocation)//今天结束fmt.Println(\"今天开始\",firstOfDay.AddDate(0,0,int(now.Day()-1)))fmt.Println(\"今天结束\",lastOfDay.AddDate(0,0,int(now.Day()-1)))//昨天firstOfYesterday := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, time.Local)//昨天开始lastOfYesterday := time.Date(currentYear, currentMonth, 1, 23, 59, 59, 999999999, time.Local)//昨天结束fmt.Println(\"昨天开始\",firstOfYesterday.AddDate(0,0,int(now.Day()-2)))fmt.Println(\"昨天结束\",lastOfYesterday.AddDate(0,0,int(now.Day()-2)))}