Calendar クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
週、月、年などの時間を部門単位で表します。
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 日は、 JapaneseCalendar と JapaneseLunisolarCalendarのレイワ時代の始まりを迎えています。 このような時代の変化は、これらのカレンダーを使用するすべてのアプリケーションに影響します。 詳細およびアプリケーションが影響を受けるかどうかを判断するには、「 .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 年の範囲の最後の年を取得または設定します。 |
メソッド
適用対象
こちらもご覧ください
- DateTime
- DateTimeFormatInfo
- ChineseLunisolarCalendar
- EastAsianLunisolarCalendar
- GregorianCalendar
- HebrewCalendar
- HijriCalendar
- JapaneseCalendar
- JapaneseLunisolarCalendar
- JulianCalendar
- KoreanCalendar
- KoreanLunisolarCalendar
- PersianCalendar
- TaiwanCalendar
- TaiwanLunisolarCalendar
- ThaiBuddhistCalendar
- UmAlQuraCalendar
- 予定表の操作