c#

位置:IT落伍者 >> c# >> 浏览文章

C#中怎么计算当前日期是在一年中的第几周


发布日期:2024年01月19日
 
C#中怎么计算当前日期是在一年中的第几周

方法一

private int WeekOfYear(string date)

{

DateTime curDay = ConvertToDateTime(date);

int firstdayofweek = ConvertToInt(ConvertToDateTime(curDayYearToString() + + )DayOfWeek);

int days = curDayDayOfYear;

int daysOutOneWeek = days ( firstdayofweek);

if (daysOutOneWeek <= )

{

return ;

}

else

{

int weeks = daysOutOneWeek / ;

if (daysOutOneWeek % != )

weeks ++;

return weeks + ;

}

}

方法二

SystemGlobalizationGregorianCalendar gc = new SystemGlobalizationGregorianCalendar();

int weekOfYear = gcGetWeekOfYear(DateTimeNow SystemGlobalizationCalendarWeekRuleFirstDay DayOfWeekMonday);

上一篇:ADO.NET的最佳实践技巧

下一篇:二叉树遍历算法C#实现