Export (0) Print
Expand All

GregorianCalendarTypes Enumeration

Defines the different language versions of the Gregorian calendar.

[Visual Basic]
<Serializable>
Public Enum GregorianCalendarTypes
[C#]
[Serializable]
public enum GregorianCalendarTypes
[C++]
[Serializable]
__value public enum GregorianCalendarTypes
[JScript]
public
   Serializable
enum GregorianCalendarTypes

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 GregorianCalendar 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, CalendarType can be used to determine which language versions of GregorianCalendar are supported.

Members

Member name Description
Arabic

Supported by the .NET Compact Framework.

Refers to the Arabic version of the Gregorian calendar.
Localized

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

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

Supported by the .NET Compact Framework.

Refers to the transliterated English version of the Gregorian calendar.
TransliteratedFrench

Supported by the .NET Compact Framework.

Refers to the transliterated French version of the Gregorian calendar.
USEnglish

Supported by the .NET Compact Framework.

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

Example

[Visual Basic, C#, C++] The following code example demonstrates how to determine the GregorianCalendar language version supported by the culture.

[Visual Basic] 
Imports System
Imports System.Globalization

Public Class SamplesCultureInfo

   Public Shared Sub Main()

      ' Gets the calendars supported by the ar-SA culture.
      Dim myOptCals As Calendar() = 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:")
      Dim cal As Calendar
      For Each cal In  myOptCals
         If cal.GetType() Is GetType(GregorianCalendar)  Then
            Dim myGreCal As GregorianCalendar = CType(cal, GregorianCalendar)
            Dim calType As GregorianCalendarTypes = myGreCal.CalendarType
            Console.WriteLine("   {0} ({1})", cal, calType)
         Else
            Console.WriteLine("   {0}", cal)
         End If
      Next cal

   End Sub 'Main 

End Class 'SamplesCultureInfo


'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)


[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)

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
using namespace System::Collections;

int main()
{
   // Calendar* myOptCals[] = new CultureInfo(S"ar-SA") -> OptionalCalendars;
   CultureInfo * MyCI = new CultureInfo(S"ar-SA");
   Calendar* myOptCals[] = MyCI -> OptionalCalendars;

   // Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
   Console::WriteLine(S"The ar-SA culture supports the following calendars:");
   IEnumerator* myEnum = myOptCals->GetEnumerator();
   while (myEnum->MoveNext())
   {
      Calendar* cal = __try_cast<Calendar*>(myEnum->Current);
      if (cal -> GetType() == __typeof(GregorianCalendar))
      {
         GregorianCalendar * myGreCal = dynamic_cast<GregorianCalendar*>(cal);
         GregorianCalendarTypes calType = myGreCal -> CalendarType;
         Console::WriteLine(S" {0} ( {1})", cal, __box(calType));
      }
      else
         Console::WriteLine(S" {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)

*/

[Visual Basic, C#, C++] The following code example prints a DateTime using a GregorianCalendar that is localized.

[Visual Basic] 
Imports System
Imports System.Globalization

Public Class SamplesGregorianCalendar

   Public Shared Sub Main()

      ' Creates and initializes three different CultureInfo.
      Dim myCIarSA As New CultureInfo("ar-SA", False)
      Dim myCIdeDE As New CultureInfo("de-DE", False)
      Dim myCIenUS As New CultureInfo("en-US", False)
      Dim myCIfrFR As New CultureInfo("fr-FR", False)

      ' Creates a Localized GregorianCalendar.
      ' GregorianCalendarTypes.Localized is the default when using the GregorianCalendar constructor without parameters.
      Dim 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,
      myCIarSA.DateTimeFormat.Calendar = myCal

      ' Creates a DateTime.
      Dim myDT As New DateTime(2002, 1, 3, 13, 30, 45)

      ' Displays the DateTime.
      Console.WriteLine("ar-SA: {0}", myDT.ToString("F", myCIarSA))
      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))

   End Sub 'Main 

End Class 'SamplesGregorianCalendar


'This code produces the following output. The question marks take the place of native script characters.
'
'ar-SA: 03 ?????, 2002 01:30:45 ?
'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


[C#] 
using System;
using System.Globalization;


public class SamplesGregorianCalendar  {

   public static void Main()  {

      // Creates and initializes three different CultureInfo.
      CultureInfo myCIarSA = new CultureInfo("ar-SA", false);
      CultureInfo myCIdeDE = new CultureInfo("de-DE", false);
      CultureInfo myCIenUS = new CultureInfo("en-US", false);
      CultureInfo myCIfrFR = new CultureInfo("fr-FR", 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,
      myCIarSA.DateTimeFormat.Calendar = myCal;

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

      // Displays the DateTime.
      Console.WriteLine( "ar-SA: {0}", myDT.ToString( "F", myCIarSA ) );
      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 ) );

   }

}

/*
This code produces the following output. The question marks take the place of native script characters.

ar-SA: 03 ?????, 2002 01:30:45 ?
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

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Creates and initializes three different CultureInfo.
   CultureInfo* myCIarSA = new CultureInfo(S"ar-SA", false);
   CultureInfo* myCIdeDE = new CultureInfo(S"de-DE", false);
   CultureInfo* myCIenUS = new CultureInfo(S"en-US", false);
   CultureInfo* myCIfrFR = new CultureInfo(S"fr-FR", false);

   // Creates a Localized GregorianCalendar.
   // GregorianCalendarTypes::Localized is the default when using the GregorianCalendar constructor with->Item[Out] 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,
   myCIarSA -> DateTimeFormat -> Calendar = myCal;

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

   // Displays the DateTime.
   Console::WriteLine(S"ar-SA: {0}", myDT.ToString(S"F", myCIarSA));
   Console::WriteLine(S"de-DE: {0}", myDT.ToString(S"F", myCIdeDE));
   Console::WriteLine(S"en-US: {0}", myDT.ToString(S"F", myCIenUS));
   Console::WriteLine(S"fr-FR: {0}", myDT.ToString(S"F", myCIfrFR));
}

/*
This code produces the following output. The question marks take the place of native script characters.

ar-SA: 03 ?????, 2002 01:30:45 ?
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

*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Globalization

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

System.Globalization Namespace

Show:
© 2014 Microsoft