共用方式為


GregorianCalendar 建構函式

定義

初始化 GregorianCalendar 類別的新執行個體。

多載

GregorianCalendar()

使用預設的 GregorianCalendar 值來初始化 GregorianCalendarTypes 類別的新執行個體。

GregorianCalendar(GregorianCalendarTypes)

使用指定的 GregorianCalendarTypes 值,初始化 GregorianCalendar 類別的新執行個體。

GregorianCalendar()

來源:
GregorianCalendar.cs
來源:
GregorianCalendar.cs
來源:
GregorianCalendar.cs

使用預設的 GregorianCalendar 值來初始化 GregorianCalendarTypes 類別的新執行個體。

public:
 GregorianCalendar();
public GregorianCalendar ();
Public Sub New ()

範例

下列程式代碼範例會 DateTime 使用 GregorianCalendar 本地化的 列印 。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes three different CultureInfo.
   CultureInfo^ myCIdeDE = gcnew CultureInfo( "de-DE",false );
   CultureInfo^ myCIenUS = gcnew CultureInfo( "en-US",false );
   CultureInfo^ myCIfrFR = gcnew CultureInfo( "fr-FR",false );
   CultureInfo^ myCIruRU = gcnew CultureInfo( "ru-RU",false );
   
   // Creates a Localized GregorianCalendar.
   // GregorianCalendarTypes::Localized is the default when using the GregorianCalendar constructor with->Item[Out] parameters.
   Calendar^ myCal = gcnew 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 = 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
*/
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
*/
Imports System.Globalization

Public Class SamplesGregorianCalendar

   Public Shared Sub Main()
      ' Creates and initializes three different CultureInfo.
      Dim myCIdeDE As New CultureInfo("de-DE", False)
      Dim myCIenUS As New CultureInfo("en-US", False)
      Dim myCIfrFR As New CultureInfo("fr-FR", False)
      Dim myCIruRU As New CultureInfo("ru-RU", 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,
      myCIruRU.DateTimeFormat.Calendar = myCal

      ' Creates a DateTime.
      Dim myDT As 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))
   End Sub
End Class
' This 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

備註

預設的 GregorianCalendarTypes 值為 Localized。 如果 的 DateTimeFormatInfo.CalendarCultureInfo 屬性設定為 GregorianCalendar 使用這個建構函式建立的 ,則日期和時間會以與 CultureInfo相關聯的語言當地語系化。

另請參閱

適用於

GregorianCalendar(GregorianCalendarTypes)

來源:
GregorianCalendar.cs
來源:
GregorianCalendar.cs
來源:
GregorianCalendar.cs

使用指定的 GregorianCalendarTypes 值,初始化 GregorianCalendar 類別的新執行個體。

public:
 GregorianCalendar(System::Globalization::GregorianCalendarTypes type);
public GregorianCalendar (System.Globalization.GregorianCalendarTypes type);
new System.Globalization.GregorianCalendar : System.Globalization.GregorianCalendarTypes -> System.Globalization.GregorianCalendar
Public Sub New (type As GregorianCalendarTypes)

參數

type
GregorianCalendarTypes

GregorianCalendarTypes 值,代表要建立曆法的哪個語言版本。

例外狀況

type 不是 GregorianCalendarTypes 列舉的成員。

另請參閱

適用於