JapaneseCalendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) 메서드

정의

지정된 DateTime의 날짜가 포함된 주(연도 기준)를 반환합니다.

public:
 override int GetWeekOfYear(DateTime time, System::Globalization::CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
public override int GetWeekOfYear (DateTime time, System.Globalization.CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetWeekOfYear (DateTime time, System.Globalization.CalendarWeekRule rule, DayOfWeek firstDayOfWeek);
override this.GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
Public Overrides Function GetWeekOfYear (time As DateTime, rule As CalendarWeekRule, firstDayOfWeek As DayOfWeek) As Integer

매개 변수

time
DateTime

읽을 DateTime입니다.

rule
CalendarWeekRule

주를 정의하는 CalendarWeekRule 값 중 하나입니다.

firstDayOfWeek
DayOfWeek

주의 첫째 요일을 나타내는 DayOfWeek 값 중 하나입니다.

반환

time 매개 변수의 날짜가 포함된 주(연도 기준)를 나타내는 1부터 시작하는 정수입니다.

특성

예외

time 또는 firstDayOfWeek가 달력에서 지원하는 범위 밖에 있는 경우

또는

rule는 유효한 CalendarWeekRule 값이 아닙니다.

예제

다음 코드 예제에서는 의 결과가 GetWeekOfYear 사용된 및 CalendarWeekRule 값에 FirstDayOfWeek 따라 어떻게 달라지는지 보여 줍니다. 지정된 날짜가 연도의 마지막 날인 경우 는 해당 연도 GetWeekOfYear 의 총 주 수를 반환합니다.

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).

설명

이 메서드는 매개 변수를 연도의 마지막 날로 설정 time 하여 연도의 주 수를 결정하는 데 사용할 수 있습니다.

속성에는 CultureInfo.DateTimeFormatfirstDayOfWeek 매개 변수에 사용할 수 있는 문화권별 값이 rule 포함되어 있습니다.

의 속성에는 FirstDayOfWeek 의 속성CultureInfo.DateTimeFormat에 지정된 달력을 사용하여 특정 문화권의 요일을 나타내는 기본값 DayOfWeekCalendar 포함 CultureInfo.DateTimeFormat 됩니다.

CultureInfo.DateTimeFormat 속성에는 CalendarWeekRule 의 속성CultureInfo.DateTimeFormat에 지정된 달력을 사용하여 특정 문화권의 달력 주를 정의하는 기본 CalendarWeekRule 값이 Calendar 포함됩니다.

예를 들어 에서 GregorianCalendar1월 1일의 메서드는 GetWeekOfYear 1을 반환합니다.

적용 대상