This documentation is archived and is not being maintained.

GregorianCalendar Constructor

.NET Framework 1.1

Initializes a new instance of the GregorianCalendar class.

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New()
[C#] public GregorianCalendar();
[C++] public: GregorianCalendar();
[JScript] public function GregorianCalendar();

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(GregorianCalendarTypes)
[C#] public GregorianCalendar(GregorianCalendarTypes);
[C++] public: GregorianCalendar(GregorianCalendarTypes);
[JScript] public function GregorianCalendar(GregorianCalendarTypes);

Example

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

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the GregorianCalendar constructor. For other examples that might be available, see the individual overload topics.
[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.

See Also

GregorianCalendar Class | GregorianCalendar Members | System.Globalization Namespace

Show: