다음을 통해 공유


Calendar.GetWeekOfYear 메서드

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

네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Overridable Function GetWeekOfYear ( _
    time As DateTime, _
    rule As CalendarWeekRule, _
    firstDayOfWeek As DayOfWeek _
) As Integer
‘사용 방법
Dim instance As Calendar
Dim time As DateTime
Dim rule As CalendarWeekRule
Dim firstDayOfWeek As DayOfWeek
Dim returnValue As Integer

returnValue = instance.GetWeekOfYear(time, rule, firstDayOfWeek)
public virtual int GetWeekOfYear (
    DateTime time,
    CalendarWeekRule rule,
    DayOfWeek firstDayOfWeek
)
public:
virtual int GetWeekOfYear (
    DateTime time, 
    CalendarWeekRule rule, 
    DayOfWeek firstDayOfWeek
)
public int GetWeekOfYear (
    DateTime time, 
    CalendarWeekRule rule, 
    DayOfWeek firstDayOfWeek
)
public function GetWeekOfYear (
    time : DateTime, 
    rule : CalendarWeekRule, 
    firstDayOfWeek : DayOfWeek
) : int

매개 변수

  • firstDayOfWeek
    주의 첫째 요일을 정의하는 DayOfWeek 값입니다.

반환 값

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

예외

예외 형식 조건

ArgumentOutOfRangeException

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

- 또는 -

rule이 유효한 CalendarWeekRule 값이 아닌 경우

설명

이 메서드를 사용하여 time을 연도의 마지막 날짜로 설정하여 연간 주 수를 결정할 수도 있습니다.

CultureInfo.DateTimeFormat 속성에는 rule 및 firstDayOfWeek에 사용할 수 있는 culture 고유의 값이 포함되어 있습니다.

CultureInfo.DateTimeFormatFirstDayOfWeek 속성에는 CultureInfo.DateTimeFormatCalendar 속성에 지정된 달력을 사용하여 특정 culture에서 한 주의 첫 번째 요일을 나타내는 기본 DayOfWeek 값이 포함되어 있습니다.

CultureInfo.DateTimeFormatCalendarWeekRule 속성에는 CultureInfo.DateTimeFormatCalendar 속성에 지정된 달력을 사용하여 특정 culture에 대해 한 주를 정의하는 기본 CalendarWeekRule 값이 포함되어 있습니다.

예를 들어, GregorianCalendar에서 GetWeekOfYear 메서드는 1월 1일에 대해 1을 반환합니다.

예제

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

Imports System
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 'Main 
End Class 'SamplesCalendar


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

*/
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).
*/
import System.* ;
import System.Globalization.* ;

public class SamplesCalendar
{
    public static void main(String[] args)
    {
        // Gets the Calendar instance associated with a CultureInfo.
        CultureInfo myCI =  new CultureInfo("en-US");
        Calendar myCal = myCI.get_Calendar();

        // Gets the DTFI properties required by GetWeekOfYear.
        CalendarWeekRule myCWR = 
            myCI.get_DateTimeFormat().get_CalendarWeekRule();
        DayOfWeek myFirstDOW = myCI.get_DateTimeFormat().get_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.", System.Convert.ToString( myCal.GetWeekOfYear(
            DateTime.get_Now(),myCWR, myFirstDOW)));

        // Displays the total number of weeks in the current year.
        DateTime LastDay = 
            new System.DateTime(DateTime.get_Now().get_Year(), 12, 31);
        Console.WriteLine("There are {0} weeks in the current year ({1}).",
            System.Convert.ToString(myCal.GetWeekOfYear(LastDay, myCWR, 
            myFirstDOW)),System.Convert.ToString( LastDay.get_Year()));
    } //main 
} //SamplesCalendar

/*
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 15 of the current year.
There are 53 weeks in the current year (2004).
*/

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Calendar 클래스
Calendar 멤버
System.Globalization 네임스페이스
System.DateTime
CalendarWeekRule
System.DayOfWeek
GetEra
GetYear
GetMonth
GetDayOfYear
GetDayOfMonth
GetDayOfWeek
GetHour
GetMinute
GetSecond
GetMilliseconds