GregorianCalendar Class
namespace System.Globalization
Overview
The GregorianCalendar
class represents the Gregorian calendar, which is the most widely used civil calendar today. It provides methods to calculate dates, months, years, and eras according to the Gregorian system.
Inheritance
Object
> Calendar
> GregorianCalendar
Constructors
Signature | Description |
---|---|
GregorianCalendar() |
Initializes a new instance of the GregorianCalendar class using the GregorianCalendarTypes.Localized type. |
GregorianCalendar(GregorianCalendarTypes type) |
Initializes a new instance with the specified GregorianCalendarTypes . |
Properties
Name | Type | Description |
---|---|---|
AlgorithmType | CalendarAlgorithmType | Gets the algorithm type used by the calendar. |
CalendarType | CalendarType | Gets the calendar type identifier. |
MaxSupportedDateTime | DateTime | Maximum date and time supported by the calendar. |
MinSupportedDateTime | DateTime | Minimum date and time supported by the calendar. |
TwoDigitYearMax | int | Gets or sets the last year of a 100-year range that can be represented by a two-digit year. |
Methods
Basic
Conversion
Validation
Signature | Description |
---|---|
int GetDaysInMonth(int year, int month, int era) | Returns the number of days in the specified month and year. |
int GetMonthsInYear(int year, int era) | Returns the number of months in the specified year. |
Signature | Description |
---|---|
DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) | Converts the specified date and time components to a DateTime value. |
int GetYear(DateTime time) | Returns the year component of the specified DateTime . |
Signature | Description |
---|---|
bool IsLeapYear(int year, int era) | Determines whether the specified year is a leap year. |
bool IsValidDay(int year, int month, int day, int era) | Determines whether the specified day is valid in the given month and year. |
Remarks
The Gregorian calendar is a refinement of the Julian calendar. It introduces leap year rules that skip three leap days every 400 years, making the average year length 365.2425 days.
When working with cultures that use the Gregorian calendar, the CultureInfo.Calendar
property typically returns an instance of this class.