TaiwanCalendar.GetWeekOfYear メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(False)> _ Public Overrides Function GetWeekOfYear ( _ time As DateTime, _ rule As CalendarWeekRule, _ firstDayOfWeek As DayOfWeek _ ) As Integer
Dim instance As TaiwanCalendar Dim time As DateTime Dim rule As CalendarWeekRule Dim firstDayOfWeek As DayOfWeek Dim returnValue As Integer returnValue = instance.GetWeekOfYear(time, rule, firstDayOfWeek)
[ComVisibleAttribute(false)] public override int GetWeekOfYear ( DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek )
[ComVisibleAttribute(false)] public: virtual int GetWeekOfYear ( DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek ) override
/** @attribute ComVisibleAttribute(false) */ public int GetWeekOfYear ( DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek )
ComVisibleAttribute(false) public override function GetWeekOfYear ( time : DateTime, rule : CalendarWeekRule, firstDayOfWeek : DayOfWeek ) : int
戻り値
time パラメータの日付を含む年の週を表す正の整数。


このメソッドは、その年の最後の日付を time パラメータに設定することにより、その年の週の数を確認するために使用できます。
CultureInfo.DateTimeFormat プロパティには、rule パラメータと firstDayOfWeek パラメータに使用できるカルチャ固有の値が含まれます。
CultureInfo.DateTimeFormat の FirstDayOfWeek プロパティには、CultureInfo.DateTimeFormat の Calendar プロパティで指定された暦を使用して、特定のカルチャにおける週の最初の曜日を表す既定の DayOfWeek 値が格納されます。
CultureInfo.DateTimeFormat の CalendarWeekRule プロパティには、CultureInfo.DateTimeFormat の Calendar プロパティを使用して、特定のカルチャの暦における週を定義する既定の CalendarWeekRule 値が格納されます。
たとえば、GregorianCalendar では、GetWeekOfYear メソッドは、1 月 1 日に対して 1 を返します。

使用する FirstDayOfWeek 値と CalendarWeekRule 値に応じて 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 Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TaiwanCalendar.GetWeekOfYear メソッドのページへのリンク