System.Globalization.Calendar Class

Assembly: Mscorlib.dll
Namespace: System.Globalization
Summary
Represents time in divisions, such as weeks, months, and years.
C# Syntax:
[Serializable]
public abstract class Calendar
Remarks
A calendar divides time into measures, such as weeks, months, and years. The number, length, and start of the divisions vary in each calendar.

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.

See also:
System.Globalization Namespace | DateTime | DateTimeFormatInfo | GregorianCalendar | HebrewCalendar | HijriCalendar | JapaneseCalendar | JulianCalendar | KoreanCalendar | TaiwanCalendar | ThaiBuddhistCalendar

System.Globalization.Calendar Member List:

Public Fields
CurrentEra Represents the current era for the current calendar. This field is constant.
Public Properties
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.
Public Methods
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.
Protected Constructors
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.
Protected Methods
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:


System.Globalization.Calendar Member Details

ctor #1
Summary
Initializes a new instance of the Calendar class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected Calendar();

Return to top


Field: CurrentEra
Summary
Represents the current era for the current calendar. This field is constant.
C# Syntax:
public const int CurrentEra;

Return to top


Property: Eras (read-only)
Summary
When overridden in a derived class, gets the list of eras in the current calendar.
C# Syntax:
public abstract int[] Eras {get;}

Return to top


Property: TwoDigitYearMax (read-write)
Summary
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
C# Syntax:
public virtual int TwoDigitYearMax {get; set;}
Remarks
This property allows a 2-digit year to be properly translated to a 4-digit year. For example, if this property is set to 2029, the 100-year range is from 1930 to 2029; therefore, a 2-digit value of 30 is interpreted as 1930, while a 2-digit value of 29 is interpreted as 2029.

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.

See also:
Calendar.ToFourDigitYear

Return to top


Method: AddDays(
   DateTime time,
   int days
)
Summary
Returns a DateTime that is the specified number of days away from the specified DateTime.
C# Syntax:
public virtual DateTime AddDays(
   DateTime time,
   int days
);
Parameters:

time

The DateTime to which to add days.

days

The number of days to add.

Return Value:
The DateTime that results from adding the specified number of days to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The days value is rounded to the nearest millisecond before it is added to the specified DateTime. If days is negative, the resulting DateTime is earlier than the specified DateTime.
See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: AddHours(
   DateTime time,
   int hours
)
Summary
Returns a DateTime that is the specified number of hours away from the specified DateTime.
C# Syntax:
public virtual DateTime AddHours(
   DateTime time,
   int hours
);
Parameters:

time

The DateTime to which to add hours.

hours

The number of hours to add.

Return Value:
The DateTime that results from adding the specified number of hours to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The hours value is rounded to the nearest millisecond before it is added to the specified DateTime. If hours is negative, the resulting DateTime is earlier than the specified DateTime.
See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddMinutes | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: AddMilliseconds(
   DateTime time,
   double milliseconds
)
Summary
Returns a DateTime that is the specified number of milliseconds away from the specified DateTime.
C# Syntax:
public virtual DateTime AddMilliseconds(
   DateTime time,
   double milliseconds
);
Parameters:

time

The DateTime to which to add milliseconds.

milliseconds

The number of milliseconds to add.

Return Value:
The DateTime that results from adding the specified number of milliseconds to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The milliseconds value is rounded to the nearest integer before it is added to the specified DateTime. If milliseconds is negative, the resulting DateTime is earlier than the specified DateTime.
See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddSeconds

Return to top


Method: AddMinutes(
   DateTime time,
   int minutes
)
Summary
Returns a DateTime that is the specified number of minutes away from the specified DateTime.
C# Syntax:
public virtual DateTime AddMinutes(
   DateTime time,
   int minutes
);
Parameters:

time

The DateTime to which to add minutes.

minutes

The number of minutes to add.

Return Value:
The DateTime that results from adding the specified number of minutes to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The minutes value is rounded to the nearest millisecond before it is added to the specified DateTime. If minutes is negative, the resulting DateTime is earlier than the specified DateTime.
See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddHours | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: AddMonths(
   DateTime time,
   int months
)
Summary
When overridden in a derived class, returns a DateTime that is the specified number of months away from the specified DateTime.
C# Syntax:
public abstract DateTime AddMonths(
   DateTime time,
   int months
);
Parameters:

time

The DateTime to which to add months.

months

The number of months to add.

Return Value:
The DateTime that results from adding the specified number of months to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The year part of the resulting DateTime is affected if the resulting month is beyond the last month of the current year. The day part of the resulting DateTime is also affected if the resulting day is not a valid day in the resulting month of the resulting year; it is changed to the last valid day in the resulting month of the resulting year. The time-of-day part of the resulting DateTime remains the same as the specified DateTime.

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.

See also:
DateTime | Calendar.AddYears | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: AddSeconds(
   DateTime time,
   int seconds
)
Summary
Returns a DateTime that is the specified number of seconds away from the specified DateTime.
C# Syntax:
public virtual DateTime AddSeconds(
   DateTime time,
   int seconds
);
Parameters:

time

The DateTime to which to add seconds.

seconds

The number of seconds to add.

Return Value:
The DateTime that results from adding the specified number of seconds to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The value parameter is rounded to the nearest millisecond before it is added to the specified DateTime. If value is negative, the resulting DateTime is earlier than the specified DateTime.
See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddMilliseconds

Return to top


Method: AddWeeks(
   DateTime time,
   int weeks
)
Summary
Returns a DateTime that is the specified number of weeks away from the specified DateTime.
C# Syntax:
public virtual DateTime AddWeeks(
   DateTime time,
   int weeks
);
Parameters:

time

The DateTime to which to add weeks.

weeks

The number of weeks to add.

Return Value:
The DateTime that results from adding the specified number of weeks to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
If weeks is negative, the resulting DateTime is earlier than the specified DateTime.

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.

See also:
DateTime | Calendar.AddYears | Calendar.AddMonths | Calendar.AddDays | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: AddYears(
   DateTime time,
   int years
)
Summary
When overridden in a derived class, returns a DateTime that is the specified number of years away from the specified DateTime.
C# Syntax:
public abstract DateTime AddYears(
   DateTime time,
   int years
);
Parameters:

time

The DateTime to which to add years.

years

The number of years to add.

Return Value:
The DateTime that results from adding the specified number of years to the specified DateTime.
Exceptions
Exception Type Condition
ArgumentException The resulting DateTime is outside the supported range.
Remarks
The day part of the resulting DateTime is affected if the resulting day is not a valid day in the resulting month of the resulting year; it is changed to the last valid day in the resulting month of the resulting year. The time-of-day part of the resulting DateTime remains the same as the specified DateTime.

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.

See also:
DateTime | Calendar.AddMonths | Calendar.AddWeeks | Calendar.AddDays | Calendar.AddHours | Calendar.AddMinutes | Calendar.AddSeconds | Calendar.AddMilliseconds

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Calendar();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetDayOfMonth(
   DateTime time
)
Summary
When overridden in a derived class, returns the day of the month in the specified DateTime.
C# Syntax:
public abstract int GetDayOfMonth(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the day of the month in time.
See also:
DateTime.Day | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetDayOfWeek(
   DateTime time
)
Summary
When overridden in a derived class, returns the day of the week in the specified DateTime.
C# Syntax:
public abstract DayOfWeek GetDayOfWeek(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
A DayOfWeek value that represents the day of the week in time.
Remarks
The DayOfWeek values are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
See also:
DateTime.DayOfWeek | DayOfWeek | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetDayOfYear(
   DateTime time
)
Summary
When overridden in a derived class, returns the day of the year in the specified DateTime.
C# Syntax:
public abstract int GetDayOfYear(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the day of the year in time.
See also:
DateTime.DayOfYear | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Overloaded Method: GetDaysInMonth(
   int year,
   int month
)
Summary
Returns the number of days in the specified month in the specified year in the current era.
C# Syntax:
public virtual int GetDaysInMonth(
   int year,
   int month
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

Return Value:
The number of days in the specified month in the specified year in the current era.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.

-or-

month is outside the range supported by the calendar.

Remarks
For example, in the Gregorian calendar, this method returns 28 or 29 for February (month = 2), depending on whether year is a leap year.
See also:
GregorianCalendar | Calendar.GetMonthsInYear | Calendar.GetDaysInYear

Return to top


Overloaded Method: GetDaysInMonth(
   int year,
   int month,
   int era
)
Summary
When overridden in a derived class, returns the number of days in the specified month in the specified year in the specified era.
C# Syntax:
public abstract int GetDaysInMonth(
   int year,
   int month,
   int era
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

era

An integer that represents the era.

Return Value:
The number of days in the specified month in the specified year in the specified era.
Exceptions
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.

Remarks
For example, in the Gregorian calendar, this method returns 28 or 29 for February (month = 2), depending on whether year is a leap year.
See also:
GregorianCalendar | Calendar.Eras | Calendar.GetMonthsInYear | Calendar.GetDaysInYear

Return to top


Overloaded Method: GetDaysInYear(
   int year
)
Summary
Returns the number of days in the specified year in the current era.
C# Syntax:
public virtual int GetDaysInYear(
   int year
);
Parameters:

year

An integer that represents the year.

Return Value:
The number of days in the specified year in the current era.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.
Remarks
For example, in the Gregorian calendar, this method returns 365 or 366, depending on whether year is a leap year.
See also:
GregorianCalendar | Calendar.GetMonthsInYear | Calendar.GetDaysInMonth

Return to top


Overloaded Method: GetDaysInYear(
   int year,
   int era
)
Summary
When overridden in a derived class, returns the number of days in the specified year in the specified era.
C# Syntax:
public abstract int GetDaysInYear(
   int year,
   int era
);
Parameters:

year

An integer that represents the year.

era

An integer that represents the era.

Return Value:
The number of days in the specified year in the specified era.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar. -or-

era is outside the range supported by the calendar.

Remarks
For example, in the Gregorian calendar, this method returns 365 or 366, depending on whether year is a leap year.
See also:
GregorianCalendar | Calendar.Eras | Calendar.GetMonthsInYear | Calendar.GetDaysInMonth

Return to top


Method: GetEra(
   DateTime time
)
Summary
When overridden in a derived class, returns the era in the specified DateTime.
C# Syntax:
public abstract int GetEra(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the era in time.
See also:
DateTime | Calendar.Eras | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHour(
   DateTime time
)
Summary
Returns the hours value in the specified DateTime.
C# Syntax:
public virtual int GetHour(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer from 0 to 23 that represents the hour in time.
See also:
DateTime.Hour | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetMilliseconds(
   DateTime time
)
Summary
Returns the milliseconds value in the specified DateTime.
C# Syntax:
public virtual double GetMilliseconds(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the milliseconds in time.
Remarks
The returned value is an integer from 0 to 999.
See also:
DateTime.Millisecond | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond

Return to top


Method: GetMinute(
   DateTime time
)
Summary
Returns the minutes value in the specified DateTime.
C# Syntax:
public virtual int GetMinute(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the minutes in time.
Remarks
The returned value is an integer from 0 to 59.
See also:
DateTime.Minute | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetMonth(
   DateTime time
)
Summary
When overridden in a derived class, returns the month in the specified DateTime.
C# Syntax:
public abstract int GetMonth(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the month in time.
See also:
DateTime.Month | Calendar.GetEra | Calendar.GetYear | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Overloaded Method: GetMonthsInYear(
   int year
)
Summary
Returns the number of months in the specified year in the current era.
C# Syntax:
public virtual int GetMonthsInYear(
   int year
);
Parameters:

year

An integer that represents the year.

Return Value:
The number of months in the specified year in the current era.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.
See also:
Calendar.GetDaysInYear | Calendar.GetDaysInMonth

Return to top


Overloaded Method: GetMonthsInYear(
   int year,
   int era
)
Summary
When overridden in a derived class, returns the number of months in the specified year in the specified era.
C# Syntax:
public abstract int GetMonthsInYear(
   int year,
   int era
);
Parameters:

year

An integer that represents the year.

era

An integer that represents the era.

Return Value:
The number of months in the specified year in the specified era.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.

-or-

era is outside the range supported by the calendar.

See also:
Calendar.Eras | Calendar.GetDaysInYear | Calendar.GetDaysInMonth

Return to top


Method: GetSecond(
   DateTime time
)
Summary
Returns the seconds value in the specified DateTime.
C# Syntax:
public virtual int GetSecond(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the seconds in time.
Remarks
The returned value is an integer from 0 to 59.
See also:
DateTime.Second | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetMilliseconds

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetWeekOfYear(
   DateTime time,
   CalendarWeekRule rule,
   DayOfWeek firstDayOfWeek
)
Summary
Returns the week of the year that includes the date in the specified DateTime.
C# Syntax:
public virtual int GetWeekOfYear(
   DateTime time,
   CalendarWeekRule rule,
   DayOfWeek firstDayOfWeek
);
Parameters:

time

The DateTime to read.

rule

A CalendarWeekRule value that defines a calendar week.

firstDayOfWeek

A DayOfWeek value that represents the first day of the week.

Return Value:
An integer that represents the week of the year that includes the date in time.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException firstDayOfWeek is outside the range supported by the calendar.

-or-

rule is not a valid CalendarWeekRule value.

Remarks
DateTimeFormatInfo.FirstDayOfWeek of CultureInfo.DateTimeFormat contains the default DayOfWeek value that represents the first day of the week for a specific culture.

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.

See also:
DateTime | CalendarWeekRule | DayOfWeek | Calendar.GetEra | Calendar.GetYear | Calendar.GetMonth | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Method: GetYear(
   DateTime time
)
Summary
When overridden in a derived class, returns the year in the specified DateTime.
C# Syntax:
public abstract int GetYear(
   DateTime time
);
Parameters:

time

The DateTime to read.

Return Value:
An integer that represents the year in time.
See also:
DateTime.Year | Calendar.GetEra | Calendar.GetMonth | Calendar.GetWeekOfYear | Calendar.GetDayOfYear | Calendar.GetDayOfMonth | Calendar.GetDayOfWeek | Calendar.GetHour | Calendar.GetMinute | Calendar.GetSecond | Calendar.GetMilliseconds

Return to top


Overloaded Method: IsLeapDay(
   int year,
   int month,
   int day
)
Summary
Determines whether the specified date in the current era is a leap day.
C# Syntax:
public virtual bool IsLeapDay(
   int year,
   int month,
   int day
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

day

An integer that represents the day.

Return Value:
true if the specified day is a leap day; otherwise, false.
Exceptions
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.

Remarks
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.

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.

See also:
Calendar.GetMonthsInYear | Calendar.GetDaysInMonth | Calendar.IsLeapYear | Calendar.IsLeapMonth

Return to top


Overloaded Method: IsLeapDay(
   int year,
   int month,
   int day,
   int era
)
Summary
When overridden in a derived class, determines whether the specified date in the specified era is a leap day.
C# Syntax:
public abstract bool IsLeapDay(
   int year,
   int month,
   int day,
   int era
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

day

An integer that represents the day.

era

An integer that represents the era.

Return Value:
true if the specified day is a leap day; otherwise, false.
Exceptions
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.

Remarks
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.

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.

See also:
Calendar.Eras | Calendar.GetMonthsInYear | Calendar.GetDaysInMonth | Calendar.IsLeapYear | Calendar.IsLeapMonth

Return to top


Overloaded Method: IsLeapMonth(
   int year,
   int month
)
Summary
Determines whether the specified month in the specified year in the current era is a leap month.
C# Syntax:
public virtual bool IsLeapMonth(
   int year,
   int month
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

Return Value:
true if the specified month is a leap month; otherwise, false.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.

-or-

month is outside the range supported by the calendar.

Remarks
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.

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.

See also:
Calendar.GetMonthsInYear | Calendar.IsLeapYear | Calendar.IsLeapDay

Return to top


Overloaded Method: IsLeapMonth(
   int year,
   int month,
   int era
)
Summary
When overridden in a derived class, determines whether the specified month in the specified year in the specified era is a leap month.
C# Syntax:
public abstract bool IsLeapMonth(
   int year,
   int month,
   int era
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

era

An integer that represents the era.

Return Value:
true if the specified month is a leap month; otherwise, false.
Exceptions
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.

Remarks
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.

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.

See also:
Calendar.Eras | Calendar.GetMonthsInYear | Calendar.IsLeapYear | Calendar.IsLeapDay

Return to top


Overloaded Method: IsLeapYear(
   int year
)
Summary
Determines whether the specified year in the current era is a leap year.
C# Syntax:
public virtual bool IsLeapYear(
   int year
);
Parameters:

year

An integer that represents the year.

Return Value:
true if the specified year is a leap year; otherwise, false.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.
Remarks
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.
See also:
Calendar.IsLeapMonth | Calendar.IsLeapDay

Return to top


Overloaded Method: IsLeapYear(
   int year,
   int era
)
Summary
When overridden in a derived class, determines whether the specified year in the specified era is a leap year.
C# Syntax:
public abstract bool IsLeapYear(
   int year,
   int era
);
Parameters:

year

An integer that represents the year.

era

An integer that represents the era.

Return Value:
true if the specified year is a leap year; otherwise, false.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.

-or-

era is outside the range supported by the calendar.

Remarks
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.
See also:
Calendar.Eras | Calendar.IsLeapMonth | Calendar.IsLeapDay

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: ToDateTime(
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond
)
Summary
Returns a DateTime that is set to the specified date and time in the current era.
C# Syntax:
public virtual DateTime ToDateTime(
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

day

An integer that represents the day.

hour

An integer that represents the hour.

minute

An integer that represents the minute.

second

An integer that represents the second.

millisecond

An integer that represents the millisecond.

Return Value:
The DateTime that is set to the specified date and time in the current era.
Exceptions
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.

See also:
DateTime | Calendar.GetMonthsInYear | Calendar.GetDaysInMonth

Return to top


Overloaded Method: ToDateTime(
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond,
   int era
)
Summary
When overridden in a derived class, returns a DateTime that is set to the specified date and time in the specified era.
C# Syntax:
public abstract DateTime ToDateTime(
   int year,
   int month,
   int day,
   int hour,
   int minute,
   int second,
   int millisecond,
   int era
);
Parameters:

year

An integer that represents the year.

month

An integer that represents the month.

day

An integer that represents the day.

hour

An integer that represents the hour.

minute

An integer that represents the minute.

second

An integer that represents the second.

millisecond

An integer that represents the millisecond.

era

An integer that represents the era.

Return Value:
The DateTime that is set to the specified date and time in the current era.
Exceptions
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.

See also:
DateTime | Calendar.Eras | Calendar.GetMonthsInYear | Calendar.GetDaysInMonth

Return to top


Method: ToFourDigitYear(
   int year
)
Summary
Converts the specified two-digit year to a four-digit year by using the Calendar.TwoDigitYearMax property to determine the appropriate century.
C# Syntax:
public virtual int ToFourDigitYear(
   int year
);
Parameters:

year

A two-digit integer that represents the year to convert.

Return Value:
An integer that contains the four-digit representation of year.
Exceptions
Exception Type Condition
ArgumentException year is outside the range supported by the calendar.
Remarks
Calendar.TwoDigitYearMax is the last year in the 100-year range that can be represented by a two-digit year. The century is determined by finding the sole occurrence of the two-digit year within that 100-year range. For example, if Calendar.TwoDigitYearMax is set to 2029, the 100-year range is from 1930 to 2029; therefore, a 2-digit value of 30 is interpreted as 1930, while a 2-digit value of 29 is interpreted as 2029.
See also:
Calendar.TwoDigitYearMax

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.