Calendar クラス

定義

週、月、年などの時間を部門単位で表します。

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

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

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 日、 8:46:00:0.0) で、春分が (1999、3、20、8、46、0、0.0) に発生しました。 Calendarの実装では、特定のカレンダーの範囲内の任意の日付を同様の数値セットにマップでき、DateTimeは、CalendarおよびDateTimeFormatInfoの情報を使用して、このような数値のセットをテキスト形式にマップできます。 テキスト表現は、カルチャに依存する場合があります(たとえば、en-US カルチャの場合は "8:46 AM March 20th 1999 AD"、ISO 8601 形式の "1999-03-20T08:46:00" など)。

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

Important

日本暦の年号は天皇の治世に基づいているため、変化することが期待されます。 たとえば、2019 年 5 月 1 日は、 JapaneseCalendarJapaneseLunisolarCalendarのレイワ時代の始まりを迎えています。 このような時代の変化は、これらのカレンダーを使用するすべてのアプリケーションに影響します。 詳細およびアプリケーションが影響を受けるかどうかを判断するには、「 .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, Int32)

派生クラスでオーバーライドされた場合は、指定した月、年、および年号の日数を返します。

GetDaysInMonth(Int32, Int32)

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

GetDaysInYear(Int32, Int32)

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

GetDaysInYear(Int32)

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

GetEra(DateTime)

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

GetHashCode()

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

(継承元 Object)
GetHour(DateTime)

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

GetLeapMonth(Int32, Int32)

指定した年と年号の閏月を計算します。

GetLeapMonth(Int32)

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

GetMilliseconds(DateTime)

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

GetMinute(DateTime)

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

GetMonth(DateTime)

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

GetMonthsInYear(Int32, Int32)

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

GetMonthsInYear(Int32)

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

GetSecond(DateTime)

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

GetType()

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

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

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

GetYear(DateTime)

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

IsLeapDay(Int32, Int32, Int32, Int32)

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

IsLeapDay(Int32, Int32, Int32)

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

IsLeapMonth(Int32, Int32, Int32)

派生クラスでオーバーライドされた場合、指定した年の指定した年の指定した月が閏月かどうかを判断します。

IsLeapMonth(Int32, Int32)

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

IsLeapYear(Int32, Int32)

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

IsLeapYear(Int32)

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

MemberwiseClone()

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

(継承元 Object)
ReadOnly(Calendar)

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

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

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

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

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

ToFourDigitYear(Int32)

TwoDigitYearMax プロパティを使用して適切な世紀を決定することで、指定した年を 4 桁の年に変換します。

ToString()

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

(継承元 Object)

適用対象

こちらもご覧ください