GregorianCalendar Constructor
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Initializes a new instance of the GregorianCalendar class using the default GregorianCalendarTypes value.
Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New
public GregorianCalendar()
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.
Examples
The following code example prints a DateTime using a GregorianCalendar that is localized.
Imports System.Globalization
Public Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
' Creates and initializes four different CultureInfo objects.
Dim myCIdeDE As New CultureInfo("de-DE")
Dim myCIenUS As New CultureInfo("en-US")
Dim myCIfrFR As New CultureInfo("fr-FR")
Dim myCIruRU As New CultureInfo("ru-RU")
' 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,
myCIruRU.DateTimeFormat.Calendar = myCal
' Creates a DateTime.
Dim myDT As New DateTime(2002, 1, 3, 13, 30, 45)
' Displays the DateTime.
outputBlock.Text += String.Format("de-DE: {0}", myDT.ToString("F", myCIdeDE)) & vbCrLf
outputBlock.Text += String.Format("en-US: {0}", myDT.ToString("F", myCIenUS)) & vbCrLf
outputBlock.Text += String.Format("fr-FR: {0}", myDT.ToString("F", myCIfrFR)) & vbCrLf
outputBlock.Text += String.Format("ru-RU: {0}", myDT.ToString("F", myCIruRU)) & vbCrLf
End Sub
End Class
' 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
using System;
using System.Globalization;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
// Creates and initializes four different CultureInfo.
CultureInfo myCIdeDE = new CultureInfo("de-DE");
CultureInfo myCIenUS = new CultureInfo("en-US");
CultureInfo myCIfrFR = new CultureInfo("fr-FR");
CultureInfo myCIruRU = new CultureInfo("ru-RU");
// 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.
outputBlock.Text += String.Format("de-DE: {0}", myDT.ToString("F", myCIdeDE)) + "\n";
outputBlock.Text += String.Format("en-US: {0}", myDT.ToString("F", myCIenUS)) + "\n";
outputBlock.Text += String.Format("fr-FR: {0}", myDT.ToString("F", myCIfrFR)) + "\n";
outputBlock.Text += String.Format("ru-RU: {0}", myDT.ToString("F", myCIruRU)) + "\n";
}
}
/*
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
*/
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.