Edit

Share via


GregorianCalendarTypes Enum

Definition

Defines the different language versions of the Gregorian calendar.

C#
public enum GregorianCalendarTypes
C#
[System.Serializable]
public enum GregorianCalendarTypes
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum GregorianCalendarTypes
Inheritance
GregorianCalendarTypes
Attributes

Fields

Name Value Description
Localized 1

Refers to the localized version of the Gregorian calendar, based on the language of the CultureInfo that uses the DateTimeFormatInfo.

USEnglish 2

Refers to the U.S. English version of the Gregorian calendar.

MiddleEastFrench 9

Refers to the Middle East French version of the Gregorian calendar.

Arabic 10

Refers to the Arabic version of the Gregorian calendar.

TransliteratedEnglish 11

Refers to the transliterated English version of the Gregorian calendar.

TransliteratedFrench 12

Refers to the transliterated French version of the Gregorian calendar.

Examples

The following code example demonstrates how to determine the GregorianCalendar language version supported by the culture.

C#
using System;
using System.Globalization;

public class SamplesCultureInfo  {

   public static void Main()  {

      // Gets the calendars supported by the ar-SA culture.
      Calendar[] myOptCals = new CultureInfo("ar-SA").OptionalCalendars;

      // Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
      Console.WriteLine( "The ar-SA culture supports the following calendars:" );
      foreach ( Calendar cal in myOptCals )  {
         if ( cal.GetType() == typeof( GregorianCalendar ) )  {
            GregorianCalendar myGreCal = (GregorianCalendar) cal;
            GregorianCalendarTypes calType = myGreCal.CalendarType;
            Console.WriteLine( "   {0} ({1})", cal, calType );
         }
         else  {
            Console.WriteLine( "   {0}", cal );
         }
      }
   }
}

/*
This code produces the following output.

The ar-SA culture supports the following calendars:
   System.Globalization.HijriCalendar
   System.Globalization.GregorianCalendar (USEnglish)
   System.Globalization.GregorianCalendar (MiddleEastFrench)
   System.Globalization.GregorianCalendar (Arabic)
   System.Globalization.GregorianCalendar (Localized)
   System.Globalization.GregorianCalendar (TransliteratedFrench)

*/

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 date and time patterns associated with the GregorianCalendar vary depending on the language. If the GregorianCalendar is selected in DateTimeFormatInfo.Calendar, GregorianCalendarTypes can be used to specify which date and time patterns to use in that DateTimeFormatInfo.

For Arabic cultures, more language versions of the Gregorian calendar are available. For example, you can use the French version of GregorianCalendar using the MiddleEastFrench value.

A culture that supports GregorianCalendarTypes might not support all language versions of GregorianCalendar. The CultureInfo.Calendar and CultureInfo.OptionalCalendars properties specify the calendars supported by that culture. If GregorianCalendar is supported, GregorianCalendar.CalendarType can be used to determine which language versions of GregorianCalendar are supported.

Applies to

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