计算当前周是一年中的第几周的函数

  1. private int WeekOfYear(string date)
  2. {
  3.      DateTime curDay = Convert.ToDateTime(date);
  4.      int firstdayofweek = Convert.ToInt32(Convert.ToDateTime(curDay.Year.ToString() + "-" + "1-1").DayOfWeek);
  5.      int days = curDay.DayOfYear;
  6.      int daysOutOneWeek = days - (7 - firstdayofweek);
  7.      if (daysOutOneWeek <= 0)
  8.      {
  9.        return 1;
  10.      }
  11.      else
  12.      {
  13.        int weeks = daysOutOneWeek / 7;
  14.        if (daysOutOneWeek % 7 != 0)
  15.           weeks ++;
  16.        return weeks + 1;
  17.      }
  18. }

你可能感兴趣的:(DONET专栏,ASP.NET,ASP.NET,2.0)