ThaiBuddhistCalendar.GetWeekOfYear Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vrátí týden v roce, který obsahuje datum v zadaném 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
Parametry
- rule
- CalendarWeekRule
Jedna z CalendarWeekRule hodnot, která definuje kalendářní týden.
Návraty
Kladné celé číslo založené na 1, které představuje týden v roce, který v parametru time
obsahuje datum.
- Atributy
Výjimky
time
nebo firstDayOfWeek
je mimo rozsah podporovaný kalendářem.
-nebo-
rule
není platná CalendarWeekRule hodnota.
Příklady
Následující příklad ukazuje, jak se výsledek GetWeekOfYear metody liší v závislosti na FirstDayOfWeek použitých hodnotách a CalendarWeekRule . Pokud je zadané datum posledním dnem v roce, GetWeekOfYear vrátí celkový počet týdnů v daném roce.
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).
Poznámky
Tuto metodu můžete použít k určení počtu týdnů v roce nastavením parametru time
na poslední den v roce.
CultureInfo.DateTimeFormat obsahuje hodnoty specifické pro jazykovou verzi, které lze použít pro rule
parametry a firstDayOfWeek
.
Vlastnost FirstDayOfWeekCultureInfo.DateTimeFormat obsahuje výchozí DayOfWeek hodnotu, která představuje první den v týdnu pro konkrétní jazykovou verzi pomocí kalendáře zadaného Calendar ve vlastnosti CultureInfo.DateTimeFormat.
Vlastnost CalendarWeekRuleCultureInfo.DateTimeFormat obsahuje výchozí CalendarWeekRule hodnotu, která definuje kalendářní týden pro konkrétní jazykovou verzi pomocí kalendáře zadaného Calendar ve vlastnosti CultureInfo.DateTimeFormat.
Například v GregorianCalendarGetWeekOfYear vrátí pro 1. leden hodnotu 1.