请参考Calendar.GetWeekOfYear Method

解决方案 »

  1.   

    /// <summary>
    /// 返回一个数组长度为3的字符串数组
    /// </summary>
    /// <returns>GetWeekDay[0]=周次;GetWeekDay[1]=该周第一天;GetWeekDay[2]=该周最后一天</returns>
    public string[] GetWeekDay()
    {
    string[] inti = new string[3];
    DateTime day = DateTime.Parse(DateTime.Today.Year + "-1-1");
    System.DayOfWeek dateTime = day.DayOfWeek;
    int DayCount = DateTime.Today.DayOfYear;
    int i = ( DayCount + aa( dateTime ) -2 ) / 7 + 1;
    inti[0] = i.ToString();inti[1] = day.AddDays( DayCount -1 ).ToString("yyyy年MM月dd日");
    inti[2] = day.AddDays( DayCount + 5 ).ToString("yyyy年MM月dd日");return inti;
    }
      

  2.   

    参考
    using System;
    using System.Globalization;
    public class SamplesCalendar  {   public static void Main()  {      // Gets the Calendar instance associated with a CultureInfo.
          CultureInfo myCI = new CultureInfo("en-US");
          Calendar myCal = myCI.Calendar;      // Gets the DTFI properties required by GetWeekOfYear.
          CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
          DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;      // Displays the number of the current week relative to the beginning of the year.
          Console.WriteLine( "The CalendarWeekRule used for the en-US culture is {0}.", myCWR );
          Console.WriteLine( "The FirstDayOfWeek used for the en-US culture is {0}.", myFirstDOW );
          Console.WriteLine( "Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW ));      // Displays the total number of weeks in the current year.
          DateTime LastDay = new System.DateTime( DateTime.Now.Year, 12, 31 );
          Console.WriteLine( "There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear( LastDay, myCWR, myFirstDOW ), LastDay.Year );   }}
      

  3.   

    int i = ( DayCount + aa( dateTime ) -2 ) / 7 + 1;
    这个中的aa是什么意思呀?
      

  4.   

    不好意思,忘了写了,只是一个显示星期的函数
    private int aa( System.DayOfWeek weekday )
    {
    switch ( weekday.ToString() )
    {
    case "Sunday" :
    return 1;
    case "Monday":
    return 2;
    case "Tuesday":
    return 3;
    case "Wednesday":
    return 4;
    case "Thursday":
    return 5;
    case "Friday":
    return 6;
    case "Saturday":
    return 0;
    default:
    return 8;
    } }