12345678910111213 |
- package date
- import "time"
- // GetBeginOfTheWeek 计算给定日期所在周的周一日期
- func GetBeginOfTheWeek(t time.Time, beginFrom time.Weekday) time.Time {
- weekday := t.Weekday()
- daysToSubtract := int(weekday - beginFrom)
- if daysToSubtract < 0 {
- daysToSubtract += 7
- }
- return t.AddDate(0, 0, -daysToSubtract)
- }
|