.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);
}

你可能感兴趣的:(.net)