GregorianCalendar Constructors

Definition

Initializes a new instance of the GregorianCalendar class.

Overloads

GregorianCalendar()

Initializes a new instance of the GregorianCalendar class using the default GregorianCalendarTypes value.

GregorianCalendar(GregorianCalendarTypes)

Initializes a new instance of the GregorianCalendar class using the specified GregorianCalendarTypes value.

GregorianCalendar()

Source:
GregorianCalendar.cs
Source:
GregorianCalendar.cs
Source:
GregorianCalendar.cs

Initializes a new instance of the GregorianCalendar class using the default GregorianCalendarTypes value.

C#
public GregorianCalendar();

Examples

The following code example prints a DateTime using a GregorianCalendar that is localized.

C#
using System;
using System.Globalization;

public class SamplesGregorianCalendar  {

   public static void Main()  {

      // Creates and initializes four different CultureInfo objects.
      CultureInfo myCIdeDE = new CultureInfo("de-DE", false);
      CultureInfo myCIenUS = new CultureInfo("en-US", false);
      CultureInfo myCIfrFR = new CultureInfo("fr-FR", false);
      CultureInfo myCIruRU = new CultureInfo("ru-RU", false);

      // Creates a Localized GregorianCalendar.
      // GregorianCalendarTypes.Localized is the default when using the GregorianCalendar constructor without parameters.
      Calendar myCal = new GregorianCalendar();

      // Sets the DateTimeFormatInfo.Calendar property to a Localized GregorianCalendar.
      // Localized GregorianCalendar is the default calendar for de-DE, en-US, and fr-FR,
      myCIruRU.DateTimeFormat.Calendar = myCal;

      // Creates a DateTime.
      DateTime myDT = new DateTime( 2002, 1, 3, 13, 30, 45 );

      // Displays the DateTime.
      Console.WriteLine( "de-DE: {0}", myDT.ToString( "F", myCIdeDE ) );
      Console.WriteLine( "en-US: {0}", myDT.ToString( "F", myCIenUS ) );
      Console.WriteLine( "fr-FR: {0}", myDT.ToString( "F", myCIfrFR ) );
      Console.WriteLine( "ru-RU: {0}", myDT.ToString( "F", myCIruRU ) );
   }
}
/*
The example displays the following output:
   de-DE: Donnerstag, 3. Januar 2002 13:30:45
   en-US: Thursday, January 03, 2002 1:30:45 PM
   fr-FR: jeudi 3 janvier 2002 13:30:45
   ru-RU: 3 января 2002 г. 13:30:45
*/

Remarks

The default GregorianCalendarTypes value is Localized. If the DateTimeFormatInfo.Calendar property of the CultureInfo is set to a GregorianCalendar that is created with this constructor, the dates and times are localized in the language associated with the CultureInfo.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

GregorianCalendar(GregorianCalendarTypes)

Source:
GregorianCalendar.cs
Source:
GregorianCalendar.cs
Source:
GregorianCalendar.cs

Initializes a new instance of the GregorianCalendar class using the specified GregorianCalendarTypes value.

C#
public GregorianCalendar(System.Globalization.GregorianCalendarTypes type);

Parameters

type
GregorianCalendarTypes

The GregorianCalendarTypes value that denotes which language version of the calendar to create.

Exceptions

type is not a member of the GregorianCalendarTypes enumeration.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0