直播网站程序源码,golang计算时间段内的工作日数量

package main

import (
	"fmt"
	"time"
)

func main() {
	start, _ := time.Parse("2006-01-02", "2021-10-01")
	end, _ := time.Parse("2006-01-02", "2021-10-31")
	total, days := CalcWorkHour(start, end)
	fmt.Println(fmt.Sprintf("总计:%.2f个小时,%d天", total, days))
}

func CalcWorkHour(begin, end time.Time) (float32, int) {
	var workHour = 0.0
	var currentTime = begin
	var workingCount int
	for {
		if currentTime.After(end) {
			break
		}
		// 周六周日
		if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
			// nothing
		} else {
			workHour += 8.0
			workingCount++
		}
		currentTime = currentTime.Add(24 * time.Hour)
	}

	return float32(workHour), workingCount
}

以上就是 直播网站程序源码,golang计算时间段内的工作日数量,更多内容欢迎关注之后的文章