如何计算周别

计算周别的代码如下:

  1. private void CalWeekNo()
  2.         {
  3.             string base_day, curr_day,base_day_of_week;
  4.             DateTime DT_base;
  5.             int base_day_of_year,curr_day_of_year;
  6.             base_day = "1/1/" + dateTimePicker1.Value.Year;
  7.             curr_day = dateTimePicker1.Value.ToString();
  8.             DT_base = DateTime.Parse(base_day);
  9.             base_day_of_year = DT_base.DayOfYear;
  10.             curr_day_of_year = dateTimePicker1.Value.DayOfYear;
  11.             base_day_of_week = DT_base.DayOfWeek.ToString();
  12.             int day_dif;
  13.             day_dif = curr_day_of_year - base_day_of_year;
  14.             switch (base_day_of_week)
  15.             {
  16.                 case "Monday":                    
  17.                     weekNo_curr = day_dif / 7 + 1;
  18.                     break;
  19.            
  20.                 case "Tuesday":
  21.                     weekNo_curr = (day_dif+1) / 7 + 1;
  22.                     break;
  23.            
  24.                 case "Wednesday":
  25.                     weekNo_curr = (day_dif + 2) / 7 + 1;
  26.                     break;
  27.          
  28.          
  29.                 case "Thursday":
  30.                     weekNo_curr = (day_dif + 3) / 7 + 1;
  31.                     break;
  32.           
  33.                 case "Friday":
  34.                     weekNo_curr = (day_dif + 4) / 7 + 1;
  35.                     break;
  36.          
  37.                 case "Saturday":
  38.                     weekNo_curr = (day_dif + 5) / 7 + 1;
  39.                     break;
  40.          
  41.                 case "Sunday":
  42.                     weekNo_curr = (day_dif + 6) / 7 + 1;
  43.                     break;
  44.             }
  45.            
  46.         }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值