计算周别的代码如下:
- private void CalWeekNo()
- {
- string base_day, curr_day,base_day_of_week;
- DateTime DT_base;
- int base_day_of_year,curr_day_of_year;
- base_day = "1/1/" + dateTimePicker1.Value.Year;
- curr_day = dateTimePicker1.Value.ToString();
- DT_base = DateTime.Parse(base_day);
- base_day_of_year = DT_base.DayOfYear;
- curr_day_of_year = dateTimePicker1.Value.DayOfYear;
- base_day_of_week = DT_base.DayOfWeek.ToString();
- int day_dif;
- day_dif = curr_day_of_year - base_day_of_year;
- switch (base_day_of_week)
- {
- case "Monday":
- weekNo_curr = day_dif / 7 + 1;
- break;
- case "Tuesday":
- weekNo_curr = (day_dif+1) / 7 + 1;
- break;
- case "Wednesday":
- weekNo_curr = (day_dif + 2) / 7 + 1;
- break;
- case "Thursday":
- weekNo_curr = (day_dif + 3) / 7 + 1;
- break;
- case "Friday":
- weekNo_curr = (day_dif + 4) / 7 + 1;
- break;
- case "Saturday":
- weekNo_curr = (day_dif + 5) / 7 + 1;
- break;
- case "Sunday":
- weekNo_curr = (day_dif + 6) / 7 + 1;
- break;
- }
- }