C# 根据年月日计算周次

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

C# 根据年月日计算周次

峰海王   2020-01-21 我要评论

/https://img.qb5200.com/download-x/day:要判断的日期,WeekStart:1 周一为一周的开始, 2 周日为一周的开始
public static int WeekOfMonth(DateTime day, int WeekStart)
{
//WeekStart
//1表示 周一至周日 为一周
//2表示 周日至周六 为一周
DateTime FirstofMonth;
FirstofMonth = Convert.ToDateTime(day.Date.Year + "-" + day.Date.Month + "-" + 1);
int i = (int)FirstofMonth.Date.DayOfWeek;
if (i == 0)
{
i = 7;
}
if (WeekStart == 1)
{
return (day.Date.Day + i - 2) / 7 + 1;
}
if (WeekStart == 2)
{
return (day.Date.Day + i - 1) / 7;
}
return 0;
//错误返回值0
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们