加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang 月工作日

发布时间:2020-12-16 18:19:50 所属栏目:大数据 来源:网络整理
导读:需要引入包 "github.com/jinzhu/now" //查询一个月当中每周工作日具体日期 func WorkDayOfMonth(currentTime string ) ([] interface {}, int ) { currentDate,_ := time.Parse( "2006-01" ,currentTime) year := currentDate.Year() month,_ := strconv.Ato
需要引入包 "github.com/jinzhu/now"

//查询一个月当中每周工作日具体日期
func WorkDayOfMonth(currentTime string) ([]interface{},int) {
    currentDate,_ := time.Parse("2006-01",currentTime)
    year := currentDate.Year()
    month,_ := strconv.Atoi(currentDate.Month().String())
    count := DaysOfMonth(year,month)
    bmonth := now.New(currentDate).BeginningOfMonth()
    var monthArr []string
    var tempArr []string
    var weekArr []interface{}
    for i := 0; i < count; i++ {
        dd := bmonth.AddDate(0, 0,i)
        //除去星期天
        if dd.Weekday().String() != "Saturday" && dd.Weekday().String() != "Sunday" {
            monthArr = append(monthArr,dd.Format("2006-01-02"))
            if len(tempArr) > 0 {
                aa,_ := time.Parse("2006-01-02",tempArr[len(tempArr)-1])
                dd,_ = time.Parse("2006-01-02",dd.Format("2006-01-02"))
                if dd.Sub(aa).Hours()/24 > 1 {
                    weekArr = append(weekArr,tempArr)
                    tempArr = nil
                }
            }
            tempArr = append(tempArr,dd.Format("2006-01-02"))
        }
    }
    return weekArr,count
}

//获取月天数
func DaysOfMonth(year int,month int) (days int) {
    if month != 2 {
        if month == 4 || month == 6 || month == 9 || month == 11 {
            days = 30

        } else {
            days = 31
        }
    } else {
        if ((year%4) == 0 && (year%100) != 0) || (year%400) == 0 {
            days = 29
        } else {
            days = 28
        }
    }
    return days
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读