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

SignatureDescription
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

NameTypeDescription
AlgorithmTypeCalendarAlgorithmTypeGets the algorithm type used by the calendar.
CalendarTypeCalendarTypeGets the calendar type identifier.
MaxSupportedDateTimeDateTimeMaximum date and time supported by the calendar.
MinSupportedDateTimeDateTimeMinimum date and time supported by the calendar.
TwoDigitYearMaxintGets or sets the last year of a 100-year range that can be represented by a two-digit year.

Methods

Basic
Conversion
Validation
SignatureDescription
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.
SignatureDescription
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.
SignatureDescription
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.

See also