熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#中怎麼計算當前日期是在一年中的第幾周

2022-06-13   來源: .NET編程 

  方法一

  private   int   WeekOfYear(string   date)

  {

  DateTime   curDay   =   ConvertToDateTime(date);

  int   firstdayofweek   =   ConvertToInt(ConvertToDateTime(curDayYearToString()   +      +   )DayOfWeek);

  int   days   =   curDayDayOfYear;

  int   daysOutOneWeek   =   days      (      firstdayofweek);

  if   (daysOutOneWeek   <=   )

  {

  return   ;

  }

  else

  {

  int   weeks   =   daysOutOneWeek   /   ;

  if   (daysOutOneWeek   %      !=   )

  weeks   ++;

  return   weeks   +   ;

  }

  }

  方法二

  SystemGlobalizationGregorianCalendar   gc   =   new   SystemGlobalizationGregorianCalendar();

  int   weekOfYear   =   gcGetWeekOfYear(DateTimeNow   SystemGlobalizationCalendarWeekRuleFirstDay   DayOfWeekMonday);


From:http://tw.wingwit.com/Article/program/net/201311/12092.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.