.net 获取当前周及根据年和周获取起始结束时间

获取当前日期周数
int str = new System.Globalization.GregorianCalendar().GetWeekOfYear(System.DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);

根据周得到启示日期和截止日期
private static void GetWeekSpan(out DateTime dtBeginDate, out DateTime dtEndDate, int iWeeks)
{
int iCurrentYear = DateTime.Now.Year;
DateTime dtFirstDate = new DateTime(iCurrentYear, 1, 1);
int iDays = (iWeeks - 1) * 7;
dtFirstDate = dtFirstDate.AddDays(iDays);
int iDaysOfWeek = (int)dtFirstDate.DayOfWeek;
dtBeginDate = dtFirstDate.AddDays(-(iDaysOfWeek - 1)-1);
dtEndDate = dtFirstDate.AddDays(7 - iDaysOfWeek-1);
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。