public static int GetIso8601WeekOfYear(DateTime time)
{
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
{
time = time.AddDays(3);
}
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
int week1 = GetIso8601WeekOfYear(DateTime.Today);
int week2 = GetIso8601WeekOfYear(DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek - 6));
int week3 = GetIso8601WeekOfYear(DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek - 12));
int week4 = GetIso8601WeekOfYear(DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek - 18));
int week5 = GetIso8601WeekOfYear(DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek - 21));
No comments:
Post a Comment