ThaiBuddhistCalendar.GetWeekOfYear Methode

Definitie

Retourneert de week van het jaar dat de datum in de opgegeven DateTimedatum bevat.

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
abstract member GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
override this.GetWeekOfYear : DateTime * System.Globalization.CalendarWeekRule * DayOfWeek -> int
Public Overrides Function GetWeekOfYear (time As DateTime, rule As CalendarWeekRule, firstDayOfWeek As DayOfWeek) As Integer

Parameters

time
DateTime

De DateTime te lezen.

rule
CalendarWeekRule

Een van de CalendarWeekRule waarden waarmee een kalenderweek wordt gedefinieerd.

firstDayOfWeek
DayOfWeek

Een van de DayOfWeek waarden die de eerste dag van de week vertegenwoordigen.

Retouren

Een positief geheel getal op basis van 1 dat de week van het jaar aangeeft die de datum in de time parameter bevat.

Kenmerken

Uitzonderingen

time of firstDayOfWeek valt buiten het bereik dat wordt ondersteund door de agenda.

– of –

rule is geen geldige CalendarWeekRule waarde.

Voorbeelden

In het volgende voorbeeld ziet u hoe het resultaat van de GetWeekOfYear methode varieert, afhankelijk van de FirstDayOfWeek waarden die CalendarWeekRule worden gebruikt. Als de opgegeven datum de laatste dag van het jaar is, GetWeekOfYear wordt het totale aantal weken in dat jaar geretourneerd.

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

Opmerkingen

Deze methode kan worden gebruikt om het aantal weken in het jaar te bepalen door de time parameter in te stellen op de laatste dag van het jaar.

CultureInfo.DateTimeFormat bevat cultuurspecifieke waarden die kunnen worden gebruikt voor de rule en firstDayOfWeek parameters.

De FirstDayOfWeek eigenschap van CultureInfo.DateTimeFormat bevat de standaardwaarde DayOfWeek die de eerste dag van de week vertegenwoordigt voor een specifieke cultuur, met behulp van de kalender die is opgegeven in de Calendar eigenschap van CultureInfo.DateTimeFormat.

De CalendarWeekRule eigenschap van CultureInfo.DateTimeFormat bevat de standaardwaarde CalendarWeekRule die een kalenderweek definieert voor een specifieke cultuur, met behulp van de kalender die is opgegeven in de Calendar eigenschap van CultureInfo.DateTimeFormat.

Bijvoorbeeld, in GregorianCalendar, GetWeekOfYear voor 1 januari retourneert 1.

Van toepassing op

Zie ook