周时间开始结束时间获取
2019-07-19 本文已影响0人
funcx
// 本周几0点
func WeekDayZeroStamp(wd time.Weekday) int64 {
nowWeekDay := time.Now().Weekday()
if nowWeekDay == time.Sunday {
nowWeekDay = 7
}
if wd == time.Sunday {
wd = 7
}
v := nowWeekDay - wd
tov := time.Now().AddDate(0, 0, -int(v))
tovs := tov.Format("20060102")
t, _ := time.ParseInLocation("20060102", tovs, time.Local)
// log.Println(t)
return t.Unix()
}
// 本周几结束点
func WeekDayEndStamp(wd time.Weekday) int64 {
return WeekDayZeroStamp(wd) + (24*60*60 - 1)
}
// 本周开始及结束点
func WeekStartEndStamp() []int64 {
return []int64{WeekDayZeroStamp(time.Monday), WeekDayEndStamp(time.Sunday)}
}