美文网首页
周时间开始结束时间获取

周时间开始结束时间获取

作者: funcx | 来源:发表于2019-07-19 10:59 被阅读0次
// 本周几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)}
}

相关文章

网友评论

      本文标题:周时间开始结束时间获取

      本文链接:https://www.haomeiwen.com/subject/yurjlctx.html