ThaiBuddhistCalendar.GetWeekOfYear Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Returnerar den vecka på året som innehåller datumet i den angivna 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
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
Parametrar
- rule
- CalendarWeekRule
Ett av de CalendarWeekRule värden som definierar en kalendervecka.
Returer
Ett 1-baserat positivt heltal som representerar den vecka på året som innehåller datumet i parametern time .
- Attribut
Undantag
time eller firstDayOfWeek ligger utanför det intervall som stöds av kalendern.
-eller-
rule är inte ett giltigt CalendarWeekRule värde.
Exempel
I följande exempel visas hur resultatet av GetWeekOfYear metoden varierar beroende på vilka FirstDayOfWeek värden och CalendarWeekRule värden som används. Om det angivna datumet är den sista dagen på året GetWeekOfYear returnerar det totala antalet veckor det året.
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).
Kommentarer
Den här metoden kan användas för att fastställa antalet veckor under året genom att ange parametern time till den sista dagen på året.
CultureInfo.DateTimeFormat innehåller kulturspecifika värden som kan användas för parametrarna rule och firstDayOfWeek .
Egenskapen FirstDayOfWeek för CultureInfo.DateTimeFormat innehåller standardvärdet DayOfWeek som representerar den första dagen i veckan för en viss kultur med hjälp av kalendern som anges i Calendar egenskapen CultureInfo.DateTimeFormatför .
Egenskapen CalendarWeekRule för innehåller standardvärdet CalendarWeekRule som definierar en kalendervecka för en specifik kultur med hjälp av CultureInfo.DateTimeFormatCultureInfo.DateTimeFormatden kalender som anges i Calendar egenskapen för .
I i returnerar till exempel GregorianCalendarGetWeekOfYear för 1 januari 1.