TaiwanCalendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) TaiwanCalendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) TaiwanCalendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) TaiwanCalendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) Method

Definizione

Restituisce la settimana dell'anno che comprende la data nel valore DateTime specificato.Returns the week of the year that includes the date in the specified DateTime.

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
Public Overrides Function GetWeekOfYear (time As DateTime, rule As CalendarWeekRule, firstDayOfWeek As DayOfWeek) As Integer

Parametri

time
DateTime DateTime DateTime DateTime

Valore DateTime da leggere.The DateTime to read.

rule
CalendarWeekRule CalendarWeekRule CalendarWeekRule CalendarWeekRule

Uno dei valori CalendarWeekRule che definisce una settimana di calendario.One of the CalendarWeekRule values that defines a calendar week.

firstDayOfWeek
DayOfWeek DayOfWeek DayOfWeek DayOfWeek

Uno dei valori DayOfWeek che rappresenta il primo giorno della settimana.One of the DayOfWeek values that represents the first day of the week.

Restituisce

Valore intero positivo che rappresenta la settimana dell'anno che include la data nel parametro time.A positive integer that represents the week of the year that includes the date in the time parameter.

Eccezioni

time o firstDayOfWeek non è compreso nell'intervallo supportato dal calendario.time or firstDayOfWeek is outside the range supported by the calendar.

-oppure--or- rule non è un valore valido di CalendarWeekRule.rule is not a valid CalendarWeekRule value.

Esempi

Nell'esempio di codice seguente viene illustrato come il GetWeekOfYear risultato di varia a seconda FirstDayOfWeek dei CalendarWeekRule valori e utilizzati.The following code example shows how the result of GetWeekOfYear varies depending on the FirstDayOfWeek and CalendarWeekRule values used. Se la data specificata è l'ultimo giorno dell'anno, GetWeekOfYear restituisce il numero totale di settimane nell'anno.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).

Commenti

Questo metodo può essere utilizzato per determinare il numero di settimane nell'anno impostando il time parametro sull'ultimo giorno dell'anno.This method can be used to determine the number of weeks in the year by setting the time parameter to the last day of the year.

La CultureInfo.DateTimeFormat proprietà contiene valori specifici delle impostazioni cultura che possono essere utilizzati per rule i firstDayOfWeek parametri e.The CultureInfo.DateTimeFormat property contains culture-specific values that can be used for the rule and firstDayOfWeek parameters.

La FirstDayOfWeek proprietà di CultureInfo.DateTimeFormat contiene il valore DayOfWeek predefinito che rappresenta il primo giorno della settimana per Calendar impostazioni cultura specifiche, utilizzando il calendario specificato nella proprietà di CultureInfo.DateTimeFormat.The FirstDayOfWeek property of CultureInfo.DateTimeFormat contains the default DayOfWeek value that represents the first day of the week for a specific culture, using the calendar specified in the Calendar property of CultureInfo.DateTimeFormat.

La CalendarWeekRule proprietà di CultureInfo.DateTimeFormat contiene il valore CalendarWeekRule predefinito che definisce una settimana di calendario per Calendar impostazioni cultura specifiche, utilizzando il calendario specificato nella proprietà di CultureInfo.DateTimeFormat.The CalendarWeekRule property of CultureInfo.DateTimeFormat contains the default CalendarWeekRule value that defines a calendar week for a specific culture, using the calendar specified in the Calendar property of CultureInfo.DateTimeFormat.

Ad esempio, in GregorianCalendaril metodo GetWeekOfYear per il 1 ° gennaio restituisce 1.For example, in GregorianCalendar, the GetWeekOfYear method for January 1 returns 1.

Si applica a