Calendar クラス

定義

週、月、年などの区分で時間を表します。

public ref class Calendar abstract
public ref class Calendar abstract : ICloneable
public abstract class Calendar
public abstract class Calendar : ICloneable
[System.Serializable]
public abstract class Calendar
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Calendar : ICloneable
type Calendar = class
type Calendar = class
    interface ICloneable
[<System.Serializable>]
type Calendar = class
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Calendar = class
    interface ICloneable
Public MustInherit Class Calendar
Public MustInherit Class Calendar
Implements ICloneable
継承
Calendar
派生
属性
実装

次のコード例は、 クラスのメンバーを Calendar 示しています。

using namespace System;
using namespace System::Globalization;
void DisplayValues( Calendar^ myCal, DateTime myDT )
{
   Console::WriteLine( "   Era: {0}", myCal->GetEra( myDT ) );
   Console::WriteLine( "   Year: {0}", myCal->GetYear( myDT ) );
   Console::WriteLine( "   Month: {0}", myCal->GetMonth( myDT ) );
   Console::WriteLine( "   DayOfYear: {0}", myCal->GetDayOfYear( myDT ) );
   Console::WriteLine( "   DayOfMonth: {0}", myCal->GetDayOfMonth( myDT ) );
   Console::WriteLine( "   DayOfWeek: {0}", myCal->GetDayOfWeek( myDT ) );
   Console::WriteLine( "   Hour: {0}", myCal->GetHour( myDT ) );
   Console::WriteLine( "   Minute: {0}", myCal->GetMinute( myDT ) );
   Console::WriteLine( "   Second: {0}", myCal->GetSecond( myDT ) );
   Console::WriteLine( "   Milliseconds: {0}", myCal->GetMilliseconds( myDT ) );
   Console::WriteLine();
}

int main()
{
   
   // Sets a DateTime to April 3, 2002 of the Gregorian calendar.
   DateTime myDT = DateTime(2002,4,3,gcnew GregorianCalendar);
   
   // Uses the default calendar of the InvariantCulture.
   Calendar^ myCal = CultureInfo::InvariantCulture->Calendar;
   
   // Displays the values of the DateTime.
   Console::WriteLine( "April 3, 2002 of the Gregorian calendar:" );
   DisplayValues( myCal, myDT );
   
   // Adds 5 to every component of the DateTime.
   myDT = myCal->AddYears( myDT, 5 );
   myDT = myCal->AddMonths( myDT, 5 );
   myDT = myCal->AddWeeks( myDT, 5 );
   myDT = myCal->AddDays( myDT, 5 );
   myDT = myCal->AddHours( myDT, 5 );
   myDT = myCal->AddMinutes( myDT, 5 );
   myDT = myCal->AddSeconds( myDT, 5 );
   myDT = myCal->AddMilliseconds( myDT, 5 );
   
   // Displays the values of the DateTime.
   Console::WriteLine( "After adding 5 to each component of the DateTime:" );
   DisplayValues( myCal, myDT );
}

/*
This code produces the following output.

April 3, 2002 of the Gregorian calendar:
Era:          1
Year:         2002
Month:        4
DayOfYear:    93
DayOfMonth:   3
DayOfWeek:    Wednesday
Hour:         0
Minute:       0
Second:       0
Milliseconds: 0

After adding 5 to each component of the DateTime:
Era:          1
Year:         2007
Month:        10
DayOfYear:    286
DayOfMonth:   13
DayOfWeek:    Saturday
Hour:         5
Minute:       5
Second:       5
Milliseconds: 5

*/
using System;
using System.Globalization;

public class SamplesCalendar  {

   public static void Main()  {

      // Sets a DateTime to April 3, 2002 of the Gregorian calendar.
      DateTime myDT = new DateTime( 2002, 4, 3, new GregorianCalendar() );

      // Uses the default calendar of the InvariantCulture.
      Calendar myCal = CultureInfo.InvariantCulture.Calendar;

      // Displays the values of the DateTime.
      Console.WriteLine( "April 3, 2002 of the Gregorian calendar:" );
      DisplayValues( myCal, myDT );

      // Adds 5 to every component of the DateTime.
      myDT = myCal.AddYears( myDT, 5 );
      myDT = myCal.AddMonths( myDT, 5 );
      myDT = myCal.AddWeeks( myDT, 5 );
      myDT = myCal.AddDays( myDT, 5 );
      myDT = myCal.AddHours( myDT, 5 );
      myDT = myCal.AddMinutes( myDT, 5 );
      myDT = myCal.AddSeconds( myDT, 5 );
      myDT = myCal.AddMilliseconds( myDT, 5 );

      // Displays the values of the DateTime.
      Console.WriteLine( "After adding 5 to each component of the DateTime:" );
      DisplayValues( myCal, myDT );
   }

   public static void DisplayValues( Calendar myCal, DateTime myDT )  {
      Console.WriteLine( "   Era:          {0}", myCal.GetEra( myDT ) );
      Console.WriteLine( "   Year:         {0}", myCal.GetYear( myDT ) );
      Console.WriteLine( "   Month:        {0}", myCal.GetMonth( myDT ) );
      Console.WriteLine( "   DayOfYear:    {0}", myCal.GetDayOfYear( myDT ) );
      Console.WriteLine( "   DayOfMonth:   {0}", myCal.GetDayOfMonth( myDT ) );
      Console.WriteLine( "   DayOfWeek:    {0}", myCal.GetDayOfWeek( myDT ) );
      Console.WriteLine( "   Hour:         {0}", myCal.GetHour( myDT ) );
      Console.WriteLine( "   Minute:       {0}", myCal.GetMinute( myDT ) );
      Console.WriteLine( "   Second:       {0}", myCal.GetSecond( myDT ) );
      Console.WriteLine( "   Milliseconds: {0}", myCal.GetMilliseconds( myDT ) );
      Console.WriteLine();
   }
}


/*
This code produces the following output.

April 3, 2002 of the Gregorian calendar:
   Era:          1
   Year:         2002
   Month:        4
   DayOfYear:    93
   DayOfMonth:   3
   DayOfWeek:    Wednesday
   Hour:         0
   Minute:       0
   Second:       0
   Milliseconds: 0

After adding 5 to each component of the DateTime:
   Era:          1
   Year:         2007
   Month:        10
   DayOfYear:    286
   DayOfMonth:   13
   DayOfWeek:    Saturday
   Hour:         5
   Minute:       5
   Second:       5
   Milliseconds: 5

*/
Imports System.Globalization


Public Class SamplesCalendar   

   Public Shared Sub Main()

      ' Sets a DateTime to April 3, 2002 of the Gregorian calendar.
      Dim myDT As New DateTime(2002, 4, 3, New GregorianCalendar())

      ' Uses the default calendar of the InvariantCulture.
      Dim myCal As Calendar = CultureInfo.InvariantCulture.Calendar

      ' Displays the values of the DateTime.
      Console.WriteLine("April 3, 2002 of the Gregorian calendar:")
      DisplayValues(myCal, myDT)

      ' Adds 5 to every component of the DateTime.
      myDT = myCal.AddYears(myDT, 5)
      myDT = myCal.AddMonths(myDT, 5)
      myDT = myCal.AddWeeks(myDT, 5)
      myDT = myCal.AddDays(myDT, 5)
      myDT = myCal.AddHours(myDT, 5)
      myDT = myCal.AddMinutes(myDT, 5)
      myDT = myCal.AddSeconds(myDT, 5)
      myDT = myCal.AddMilliseconds(myDT, 5)

      ' Displays the values of the DateTime.
      Console.WriteLine("After adding 5 to each component of the DateTime:")
      DisplayValues(myCal, myDT)

   End Sub

   Public Shared Sub DisplayValues(myCal As Calendar, myDT As DateTime)
      Console.WriteLine("   Era:          {0}", myCal.GetEra(myDT))
      Console.WriteLine("   Year:         {0}", myCal.GetYear(myDT))
      Console.WriteLine("   Month:        {0}", myCal.GetMonth(myDT))
      Console.WriteLine("   DayOfYear:    {0}", myCal.GetDayOfYear(myDT))
      Console.WriteLine("   DayOfMonth:   {0}", myCal.GetDayOfMonth(myDT))
      Console.WriteLine("   DayOfWeek:    {0}", myCal.GetDayOfWeek(myDT))
      Console.WriteLine("   Hour:         {0}", myCal.GetHour(myDT))
      Console.WriteLine("   Minute:       {0}", myCal.GetMinute(myDT))
      Console.WriteLine("   Second:       {0}", myCal.GetSecond(myDT))
      Console.WriteLine("   Milliseconds: {0}", myCal.GetMilliseconds(myDT))
      Console.WriteLine()
   End Sub

End Class


'This code produces the following output.
'
'April 3, 2002 of the Gregorian calendar:
'   Era:          1
'   Year:         2002
'   Month:        4
'   DayOfYear:    93
'   DayOfMonth:   3
'   DayOfWeek:    Wednesday
'   Hour:         0
'   Minute:       0
'   Second:       0
'   Milliseconds: 0
'
'After adding 5 to each component of the DateTime:
'   Era:          1
'   Year:         2007
'   Month:        10
'   DayOfYear:    286
'   DayOfMonth:   13
'   DayOfWeek:    Saturday
'   Hour:         5
'   Minute:       5
'   Second:       5
'   Milliseconds: 5

注釈

カレンダーは、週、月、年などの単位に時間を分割します。 区分の数、長さ、開始は、カレンダーごとに異なります。

Note

.NET で予定表クラスを使用する方法については、「 予定表の操作」を参照してください。

特定のカレンダーを使用して、任意の時点を数値のセットとして表すことができます。 たとえば、グレゴリオ暦 (1999 年 3 月 20 日、 1999 年 3 月 20 日) の (1999、3、20、8、46、0.0) で、春分が 8:46:00:0.0 に発生しました。 のCalendar実装では、特定のカレンダーの範囲内の任意の日付を同様の数値セットにマップでき、 および DateTime の情報CalendarDateTimeFormatInfoを使用して、このような数値のセットをテキスト表現にマップできます。 テキスト表現は、EN-US カルチャの場合は "1999 年 3 月 20 日午前 8 時 46 分 AD" など、カルチャに依存しない場合があります (ISO 8601 形式の "1999-03-20T08:46:00" など)。

実装では Calendar 、1 つ以上の時代 (年号) を定義できます。 クラスは Calendar 、時代 () を列挙された整数として識別します。現在の時代 (CurrentEra) の値は 0 です。

重要

和暦の時代 (年号) は天皇の代に基づいているため、変更されることが予想されます。 たとえば、JapaneseCalendarJapaneseLunisolarCalendar において、2019 年 5 月 1 日から令和時代が始まることになりました。 このような時代 (年号) の変更は、これらのカレンダーを使用するすべてのアプリケーションに影響します。 詳細と、アプリケーションが影響を受けるかどうかを判断するには、「 .NET での日本語カレンダーでの新しい時代の処理」を参照してください。 Windows システムでアプリケーションをテストして時代 (年号) の変更に対する準備を確認する方法については、「 日本の時代 (年号) に合わせてアプリケーションを準備する」を参照してください。 複数の時代 (年号) を含むカレンダーをサポートする .NET の機能と、複数の時代 (年号) をサポートするカレンダーを操作する場合のベスト プラクティスについては、「 年号の操作」を参照してください。

暦年と地球が太陽の周りを回転する実際の時間、または月が地球の周りを回転する実際の時間の違いを確認するために、閏年は標準の暦年とは日数が異なります。 各 Calendar 実装では、閏年の定義が異なります。

一貫性を保つには、各間隔の最初の単位 (たとえば、最初の月) に値 1 が割り当てられます。

名前空間には System.Globalization 、次 Calendar の実装が含まれています。

コンストラクター

Calendar()

Calendar クラスの新しいインスタンスを初期化します。

フィールド

CurrentEra

現在のカレンダーの現在の時代 (年号) を表します。 このフィールドの値は 0 です。

プロパティ

AlgorithmType

現在のカレンダーの暦法 (太陽暦、太陰暦、または両者の組み合わせ) を示す値を取得します。

DaysInYearBeforeMinSupportedYear

MinSupportedDateTime プロパティで指定された年の前の年の日数を取得します。

Eras

派生クラスでオーバーライドされると、現在のカレンダーの時代 (年号) のリストを取得します。

IsReadOnly

この Calendar オブジェクトが読み取り専用かどうかを示す値を取得します。

MaxSupportedDateTime

この Calendar オブジェクトでサポートされている最も新しい日付と時刻を取得します。

MinSupportedDateTime

この Calendar オブジェクトでサポートされている最も古い日付と時刻を取得します。

TwoDigitYearMax

年の 2 桁表記で表すことができる 100 年間の範囲内で最後に当たる年を取得または設定します。

メソッド

AddDays(DateTime, Int32)

指定した DateTime から指定した日数が経過した後の DateTime を返します。

AddHours(DateTime, Int32)

指定した DateTime から指定した時間数が経過した後の DateTime を返します。

AddMilliseconds(DateTime, Double)

指定した DateTime から指定したミリ秒数が経過した後の DateTime を返します。

AddMinutes(DateTime, Int32)

指定した DateTime から指定した分数が経過した後の DateTime を返します。

AddMonths(DateTime, Int32)

派生クラスでオーバーライドされると、指定した DateTime から指定した月数が経過した後の DateTime を返します。

AddSeconds(DateTime, Int32)

指定した DateTime から指定した秒数が経過した後の DateTime を返します。

AddWeeks(DateTime, Int32)

指定した DateTime から指定した週数が経過した後の DateTime を返します。

AddYears(DateTime, Int32)

派生クラスでオーバーライドされると、指定した DateTime から指定した年数が経過した後の DateTime を返します。

Clone()

現在の Calendar オブジェクトのコピーである新しいオブジェクトを作成します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetDayOfMonth(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の月の日付を返します。

GetDayOfWeek(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の曜日を返します。

GetDayOfYear(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の年の日付を返します。

GetDaysInMonth(Int32, Int32)

現在の時代 (年号) の指定した月および年の日数を返します。

GetDaysInMonth(Int32, Int32, Int32)

派生クラスでオーバーライドされると、指定した月、年と時代 (年号) の日数を返します。

GetDaysInYear(Int32)

現在の時代 (年号) の指定した年の日数を返します。

GetDaysInYear(Int32, Int32)

派生クラスでオーバーライドされると、指定した年と時代 (年号) の日数を返します。

GetEra(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の時代 (年号) を返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetHour(DateTime)

指定した DateTime の時間の値を返します。

GetLeapMonth(Int32)

指定された年の閏月を計算します。

GetLeapMonth(Int32, Int32)

指定された年と時代 (年号) の閏月を計算します。

GetMilliseconds(DateTime)

指定した DateTime のミリ秒の値を返します。

GetMinute(DateTime)

指定した DateTime の分の値を返します。

GetMonth(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の月を返します。

GetMonthsInYear(Int32)

現在の時代 (年号) の指定した年の月数を返します。

GetMonthsInYear(Int32, Int32)

派生クラスでオーバーライドされると、指定した時代 (年号) の指定された年の月数を返します。

GetSecond(DateTime)

指定した DateTime の秒の値を返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek)

指定した DateTime 値の日付を含む年の週を返します。

GetYear(DateTime)

派生クラスでオーバーライドされると、指定した DateTime の年を返します。

IsLeapDay(Int32, Int32, Int32)

現在の時代 (年号) の指定した日付が閏日かどうかを判断します。

IsLeapDay(Int32, Int32, Int32, Int32)

派生クラスでオーバーライドされると、指定した時代 (年号) の指定した日付が閏日かどうかを判断します。

IsLeapMonth(Int32, Int32)

現在の時代 (年号) の指定した年の指定した月が閏月かどうかを判断します。

IsLeapMonth(Int32, Int32, Int32)

派生クラスでオーバーライドされると、指定した時代 (年号) の指定した年の指定した月が閏月かどうかを判断します。

IsLeapYear(Int32)

現在の時代 (年号) の指定した年が閏年かどうかを判断します。

IsLeapYear(Int32, Int32)

派生クラスでオーバーライドされると、指定した時代 (年号) の指定した年が閏年かどうかを判断します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ReadOnly(Calendar)

指定された Calendar オブジェクトの読み取り専用バージョンを返します。

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

現在の時代 (年号) の指定した日付と時刻に設定された DateTime を返します。

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

派生クラスでオーバーライドされると、指定した時代 (年号) の指定した日付と時刻に設定された DateTime を返します。

ToFourDigitYear(Int32)

TwoDigitYearMax プロパティを使用して、指定した年を 4 桁表記に変換し、適切な世紀を判断します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください