[Serializable] |
Any moment in time can be represented as a set of numeric values using a particular calendar. For example, the last vernal equinox occurred at (0.0, 0, 46, 8, 20, 3, 1999) in the Gregorian calendar. An implementation of Calendar can map any DateTime value to a similar set of numeric values, and DateTime can map such sets of numeric values to a textual representation (for example, "8:46 AM March 20th 1999 AD" for the English (United States) culture) using DateTimeFormatInfo.
A Calendar implementation can define one or more eras. The Calendar class identifies the eras as enumerated integers where the current era ( Calendar.CurrentEra) has the value 0.
In order to make up for the difference between the calendar year and the actual time that the earth rotates around the sun or the actual time that the moon rotates around the earth, a leap year has a different number of days than a standard calendar year. Each Calendar implementation defines leap years differently.
For consistency, the first unit in each interval (for example, the first month) is assigned the value 1.
The System.Globalization namespace includes the following Calendar implementations: GregorianCalendar, HebrewCalendar, HijriCalendar, JapaneseCalendar, JulianCalendar, KoreanCalendar, TaiwanCalendar, and ThaiBuddhistCalendar.
CurrentEra | Represents the current era for the current calendar. This field is constant. |
Eras | Read-only When overridden in a derived class, gets the list of eras in the current calendar. |
TwoDigitYearMax | Read-write Gets or sets the last year of a 100-year range that can be represented by a 2-digit year. |
AddDays | Returns a DateTime that is the specified number of days away from the specified DateTime. |
AddHours | Returns a DateTime that is the specified number of hours away from the specified DateTime. |
AddMilliseconds | Returns a DateTime that is the specified number of milliseconds away from the specified DateTime. |
AddMinutes | Returns a DateTime that is the specified number of minutes away from the specified DateTime. |
AddMonths | When overridden in a derived class, returns a DateTime that is the specified number of months away from the specified DateTime. |
AddSeconds | Returns a DateTime that is the specified number of seconds away from the specified DateTime. |
AddWeeks | Returns a DateTime that is the specified number of weeks away from the specified DateTime. |
AddYears | When overridden in a derived class, returns a DateTime that is the specified number of years away from the specified DateTime. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetDayOfMonth | When overridden in a derived class, returns the day of the month in the specified DateTime. |
GetDayOfWeek | When overridden in a derived class, returns the day of the week in the specified DateTime. |
GetDayOfYear | When overridden in a derived class, returns the day of the year in the specified DateTime. |
GetDaysInMonth | Overloaded:GetDaysInMonth(int year, int month) Returns the number of days in the specified month in the specified year in the current era. |
GetDaysInMonth | Overloaded:GetDaysInMonth(int year, int month, int era) When overridden in a derived class, returns the number of days in the specified month in the specified year in the specified era. |
GetDaysInYear | Overloaded:GetDaysInYear(int year) Returns the number of days in the specified year in the current era. |
GetDaysInYear | Overloaded:GetDaysInYear(int year, int era) When overridden in a derived class, returns the number of days in the specified year in the specified era. |
GetEra | When overridden in a derived class, returns the era in the specified DateTime. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetHour | Returns the hours value in the specified DateTime. |
GetMilliseconds | Returns the milliseconds value in the specified DateTime. |
GetMinute | Returns the minutes value in the specified DateTime. |
GetMonth | When overridden in a derived class, returns the month in the specified DateTime. |
GetMonthsInYear | Overloaded:GetMonthsInYear(int year) Returns the number of months in the specified year in the current era. |
GetMonthsInYear | Overloaded:GetMonthsInYear(int year, int era) When overridden in a derived class, returns the number of months in the specified year in the specified era. |
GetSecond | Returns the seconds value in the specified DateTime. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
GetWeekOfYear | Returns the week of the year that includes the date in the specified DateTime. |
GetYear | When overridden in a derived class, returns the year in the specified DateTime. |
IsLeapDay | Overloaded:IsLeapDay(int year, int month, int day) Determines whether the specified date in the current era is a leap day. |
IsLeapDay | Overloaded:IsLeapDay(int year, int month, int day, int era) When overridden in a derived class, determines whether the specified date in the specified era is a leap day. |
IsLeapMonth | Overloaded:IsLeapMonth(int year, int month) Determines whether the specified month in the specified year in the current era is a leap month. |
IsLeapMonth | Overloaded:IsLeapMonth(int year, int month, int era) When overridden in a derived class, determines whether the specified month in the specified year in the specified era is a leap month. |
IsLeapYear | Overloaded:IsLeapYear(int year) Determines whether the specified year in the current era is a leap year. |
IsLeapYear | Overloaded:IsLeapYear(int year, int era) When overridden in a derived class, determines whether the specified year in the specified era is a leap year. |
ToDateTime | Overloaded:ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) Returns a DateTime that is set to the specified date and time in the current era. |
ToDateTime | Overloaded:ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) When overridden in a derived class, returns a DateTime that is set to the specified date and time in the specified era. |
ToFourDigitYear | Converts the specified two-digit year to a four-digit year by using the Calendar.TwoDigitYearMax property to determine the appropriate century. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. Initializes a new instance of the Calendar class. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
protected Calendar(); |
public const int CurrentEra;
|
public abstract int[] Eras {get;}
|
public virtual int TwoDigitYearMax {get; set;}
|
The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel in Windows. However, that information can change during the life of the AppDomain. The Calendar class does not detect changes in the system settings automatically.
time
days
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
time
hours
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
time
milliseconds
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
time
minutes
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
time
months
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
For example, suppose that the current calendar has 12 months where the fourth month has 30 days and the tenth month has 31 days. If the specified month is the tenth month, the specified day is the 31st day of that month, and the value of the months parameter is 6, the resulting year is one more than the specified year, the resulting month is the fourth month, and the resulting day is the 30th day, which is the last day of the resulting month.
If the value of the months parameter is negative, the resulting DateTime is earlier than the specified DateTime.
time
seconds
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
time
weeks
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
In all .NET Framework classes derived from the Calendar class, a week is defined as seven days, except the first and last weeks of the year which might have less than seven days.
time
years
Exception Type | Condition |
---|---|
ArgumentException | The resulting DateTime is outside the supported range. |
For example, in the Gregorian calendar, February has 28 days, except during a leap year when it has 29 days. If the specified date is the 29th day of February in a leap year and the value of years is 1, the resulting date will be the 28th day of February in the following year.
If years is negative, the resulting DateTime is earlier than the specified DateTime.
~Calendar(); |
time
time
time
year
month
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. |
year
month
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
year
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. |
year
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
time
public virtual int GetHashCode(); |
time
time
time
time
year
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. |
year
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
time
public Type GetType(); |
public virtual int GetWeekOfYear( |
time
rule
firstDayOfWeek
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | firstDayOfWeek is outside the range supported by the calendar. -or- rule is not a valid CalendarWeekRule value. |
DateTimeFormatInfo.CalendarWeekRule of CultureInfo.DateTimeFormat contains the default CalendarWeekRule value that defines a calendar week for a specific culture.
This method can also be used to determine the number of weeks in the year by setting time to the last day of the year.
time
year
month
day
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- day is outside the range supported by the calendar. |
A leap day is a day that occurs only in a leap year. For example, in the Gregorian calendar, the 29th day of February is the only leap day.
year
month
day
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- day is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
A leap day is a day that occurs only in a leap year. For example, in the Gregorian calendar, the 29th day of February is the only leap day.
year
month
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. |
A leap month is an entire month that occurs only in a leap year. For example, in the Hebrew calendar, Veadar is the only leap month.
year
month
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
A leap month is an entire month that occurs only in a leap year. For example, in the Hebrew calendar, Veadar is the only leap month.
year
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. |
year
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- era is outside the range supported by the calendar. |
protected object MemberwiseClone(); |
public virtual DateTime ToDateTime( |
year
month
day
hour
minute
second
millisecond
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- day is outside the range supported by the calendar. -or- hour is less than zero or greater than 23. -or- minute is less than zero or greater than 59. -or- second is less than zero or greater than 59. -or- millisecond is less than zero or greater than 999. |
public abstract DateTime ToDateTime( |
year
month
day
hour
minute
second
millisecond
era
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. -or- month is outside the range supported by the calendar. -or- day is outside the range supported by the calendar. -or- hour is less than zero or greater than 23. -or- minute is less than zero or greater than 59. -or- second is less than zero or greater than 59. -or- millisecond is less than zero or greater than 999. -or- era is outside the range supported by the calendar. |
year
Exception Type | Condition |
---|---|
ArgumentException | year is outside the range supported by the calendar. |
public virtual string ToString(); |