Calendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) Method

Definition

지정된 DateTime 값의 날짜가 포함된 주(연도 기준)를 반환합니다.Returns the week of the year that includes the date in the specified DateTime value.

public:
 virtual int GetWeekOfYear(DateTime time, System::Globalization::CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
public virtual int GetWeekOfYear (DateTime time, System.Globalization.CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
abstract member GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
override this.GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
Public Overridable Function GetWeekOfYear (time As DateTime, rule As CalendarWeekRule, firstDayOfWeek As DayOfWeek) As Integer

Parameters

time
DateTime

날짜 및 시간 값입니다.A date and time value.

rule
CalendarWeekRule

주를 정의 하는 열거형 값입니다.An enumeration value that defines a calendar week.

firstDayOfWeek
DayOfWeek

주의 첫째 요일을 나타내는 열거형 값입니다.An enumeration value that represents the first day of the week.

Returns

Int32

time 매개 변수의 날짜가 포함된 주(연도 기준)를 나타내는 양의 정수입니다.A positive integer that represents the week of the year that includes the date in the time parameter.

Exceptions

timeMinSupportedDateTime보다 이전이거나 MaxSupportedDateTime보다 이후인 경우time is earlier than MinSupportedDateTime or later than MaxSupportedDateTime.

-또는--or- firstDayOfWeek은 유효한 DayOfWeek 값이 아닙니다.firstDayOfWeek is not a valid DayOfWeek value.

-또는--or- rule은 유효한 CalendarWeekRule 값이 아닙니다.rule is not a valid CalendarWeekRule value.

Examples

다음 코드 예제에서는 FirstDayOfWeek와 사용 되는 CalendarWeekRule에 따라 GetWeekOfYear 결과가 어떻게 달라 지는 지 보여 줍니다.The following code example shows how the result of GetWeekOfYear varies depending on the FirstDayOfWeek and the CalendarWeekRule used. 지정 된 날짜가 연도의 마지막 날 이면 GetWeekOfYear는 해당 연도의 총 주 수를 반환 합니다.If the specified date is the last day of the year, GetWeekOfYear returns the total number of weeks in that year.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Gets the Calendar instance associated with a CultureInfo.
   CultureInfo^ myCI = gcnew 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 = 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 );
}

/*
This code produces the following output.  Results vary depending on the system date.

The CalendarWeekRule used for the en-US culture is FirstDay.
The FirstDayOfWeek used for the en-US culture is Sunday.
Therefore, the current week is Week 1 of the current year.
There are 53 weeks in the current year (2001).
*/
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 );
   }
}

/*
This code produces the following output.  Results vary depending on the system date.

The CalendarWeekRule used for the en-US culture is FirstDay.
The FirstDayOfWeek used for the en-US culture is Sunday.
Therefore, the current week is Week 1 of the current year.
There are 53 weeks in the current year (2001).

*/
Imports System.Globalization

Public Class SamplesCalendar

   Public Shared Sub Main()
      
      ' Gets the Calendar instance associated with a CultureInfo.
      Dim myCI As New CultureInfo("en-US")
      Dim myCal As Calendar = myCI.Calendar
      
      ' Gets the DTFI properties required by GetWeekOfYear.
      Dim myCWR As CalendarWeekRule = myCI.DateTimeFormat.CalendarWeekRule
      Dim myFirstDOW As DayOfWeek = 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.
      Dim 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)
   End Sub
End Class


'This code produces the following output.  Results vary depending on the system date.
'
'The CalendarWeekRule used for the en-US culture is FirstDay.
'The FirstDayOfWeek used for the en-US culture is Sunday.
'Therefore, the current week is Week 1 of the current year.
'There are 53 weeks in the current year (2001).

Remarks

이 메서드를 사용 하 여 연간 주 수를 확인할 수 있습니다 .이 연도는 time의 마지막 날로 설정 합니다.This method can be used to determine the number of weeks in the year by setting time to the last day of the year.

DateTimeFormatInfo.Calendar 속성에 지정 된 달력을 사용 하는 특정 문화권에 대 한 DateTimeFormatInfo 개체에는 rulefirstDayOfWeek 매개 변수에 사용할 수 있는 다음과 같은 문화권 관련 값이 포함 됩니다.The DateTimeFormatInfo object for a particular culture that uses the calendar indicated by the DateTimeFormatInfo.Calendar property includes the following culture-specific values that can be used for the rule and firstDayOfWeek parameters:

다음 예제에서는 현재 문화권의 DateTimeFormatInfo 개체를 사용 하 여 2011 년 1 월 1 일이 양력에서 연도의 첫째 주에 있는지 확인 합니다.The following example uses the current culture's DateTimeFormatInfo object to determine that January 1, 2011 is in the first week of the year in the Gregorian calendar.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
      DateTime date1 = new DateTime(2011, 1, 1);
      Calendar cal = dfi.Calendar;

      Console.WriteLine("{0:d}: Week {1} ({2})", date1,
                        cal.GetWeekOfYear(date1, dfi.CalendarWeekRule,
                                          dfi.FirstDayOfWeek),
                        cal.ToString().Substring(cal.ToString().LastIndexOf(".") + 1));
   }
}
// The example displays the following output:
//       1/1/2011: Week 1 (GregorianCalendar)
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim dfi As DateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo
      Dim date1 As Date = #1/1/2011#
      Dim cal As Calendar = dfi.Calendar
      
      Console.WriteLine("{0:d}: Week {1} ({2})", date1, 
                        cal.GetWeekOfYear(date1, dfi.CalendarWeekRule, 
                                          dfi.FirstDayOfWeek),
                        cal.ToString().Substring(cal.ToString().LastIndexOf(".") + 1))       
   End Sub
End Module
' The example displays the following output:
'       1/1/2011: Week 1 (GregorianCalendar)

일부 달력의 경우 GetWeekOfYear 메서드를 호출 하면 time가 해당 달력의 MinSupportedDateTime 속성에서 반환 된 날짜 보다 큰 경우에도 rulefirstDayOfWeek 값의 특정 조합에 대해 ArgumentOutOfRangeException throw 됩니다.For some calendars, a call to the GetWeekOfYear method throws an ArgumentOutOfRangeException for particular combinations of rule and firstDayOfWeek values even if time is greater than the date returned by that calendar's MinSupportedDateTime property. 다음 표에서는 영향을 받는 달력, 특정 rule 값 및 가장 이른 지원 time 값의 범위를 나열 합니다.The following table lists the affected calendars, the specific rule values, and the range of the earliest supported time values. 지정 된 최소 DateTime 값은 firstDayOfWeek 매개 변수의 값에 따라 달라 집니다.The specific minimum DateTime value depends on the value of the firstDayOfWeek parameter.

달력Calendar CalendarWeekRule 값CalendarWeekRule value 양력 날짜 (M/dd/yyyy)Gregorian date (M/dd/yyyy) (M/dd/yyyy) 달력의 날짜Date in calendar (M/dd/yyyy)
ChineseLunisolarCalendar FirstFullWeek 1901/2/19부터 1901/25/22/19/1901 to 2/25/1901 1901/1/7을 1901 년 1/1 /1/1/1901 to 1/7/1901
ChineseLunisolarCalendar FirstFourDayWeek 1901/2/19부터 1901/22/22/19/1901 to 2/22/1901 1901/1/01부터 1/04/19011/01/1901 to 1/04/1901
HebrewCalendar FirstDay 9/17/15839/17/1583 1/01/53441/01/5344
HebrewCalendar FirstFullWeek 1583/9/17부터 1583/9/239/17/1583 to 9/23/1583 1/01/5344를 1/07/53441/01/5344 to 1/07/5344
HebrewCalendar FirstFourDayWeek 1583/9/17부터 1583/9/209/17/1583 to 9/20/1583 1/01/5344를 1/04/53441/01/5344 to 1/04/5344
HijriCalendar FirstFullWeek 7/18/0622를 7/24/06227/18/0622 to 7/24/0622 1/01/0001 1/07/0001를1/01/0001 to 1/07/0001
HijriCalendar FirstFourDayWeek 7/18/0622를 7/21/06227/18/0622 to 7/21/0622 1/01/0001 1/04/0001를1/01/0001 to 1/04/0001
JapaneseLunisolarCalendar FirstFullWeek 1960/1/28부터 1960/2/031/28/1960 to 2/03/1960 35/1/01부터 0035/1/071/01/35 to 1/07/0035
JapaneseLunisolarCalendar FirstFourDayWeek 1960/1/28부터 1/31/19601/28/1960 to 1/31/1960 1/04/0035를 볼 수 1/01 /1/01/0035 to 1/04/0035
JulianCalendar FirstFullWeek 1/01/0001 1/05/0001를1/01/0001 to 1/05/0001 1/07/0001를 0001/1/031/03/0001 to 1/07/0001
JulianCalendar FirstFourDayWeek 1/01/0001 1/02/0001를1/01/0001 to 1/02/0001 1/04/0001를 0001/1/031/03/0001 to 1/04/0001
KoreanLunisolarCalendar FirstFullWeek 2/14/0918에 2/20/09182/14/0918 to 2/20/0918 1/01/0918를 1/07/09181/01/0918 to 1/07/0918
KoreanLunisolarCalendar FirstFourDayWeek 2/14/0918에 2/17/09182/14/0918 to 2/17/0918 1/01/0918를 1/04/09181/01/0918 to 1/04/0918
PersianCalendar FirstFullWeek 0622/21/3에 3/27/06223/21/0622 to 3/27/0622 1/01/0001 1/07/0001를1/01/0001 to 1/07/0001
PersianCalendar FirstFourDayWeek 0622/21/3에 3/24/06223/21/0622 to 3/24/0622 1/01/0001 1/04/0001를1/01/0001 to 1/04/0001
TaiwanLunisolarCalendar FirstFullWeek 1912/2/18 일까 지/2/24/19122/18/1912 to 2/24/1912 1/01/0001 1/07/0001를1/01/0001 to 1/07/0001
TaiwanLunisolarCalendar FirstFourDayWeek 1912/2/18 일까 지/2/21/19122/18/1912 to 2/21/1912 1/01/0001 1/04/0001를1/01/0001 to 1/04/0001
UmAlQuraCalendar FirstFullWeek 5/06/1900을 1900 년 4 월 30 일4/30/1900 to 5/06/1900 1318/1/01부터 1318/1/071/01/1318 to 1/07/1318
UmAlQuraCalendar FirstFourDayWeek 1900 년 5 월 03을 1900 년 4 월 30 일4/30/1900 to 5/03/1900 1318/1/01부터 1/04/13181/01/1318 to 1/04/1318

Applies to

See also