GregorianCalendar 类

表示公历。

**命名空间:**System.Globalization
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class GregorianCalendar
    Inherits Calendar
用法
Dim instance As GregorianCalendar
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class GregorianCalendar : Calendar
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class GregorianCalendar : public Calendar
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class GregorianCalendar extends Calendar
SerializableAttribute 
ComVisibleAttribute(true) 
public class GregorianCalendar extends Calendar

备注

公历识别两种纪元:B.C.(公元前)或 B.C.E.(基督纪元前)和 A.D.(即拉丁语“Anno Domini”,意为“上帝之年”)或 C.E.(基督纪元)。GregorianCalendar 类的此实现只识别当前纪元(A.D. 或 C.E.)。

公历中的闰年定义为:除可被 100 整除的年份外,可以被 4 整除的年份是闰年;在可被 100 整除的年份中,可以被 400 整除的年份是闰年。例如,1900 年不是闰年,但 2000 年是闰年。平年有 365 天,闰年有 366 天。

公历有 12 个月,每个月 28 到 31 天不等:1 月(31 天)、2 月(28 或 29 天)、3 月(31 天)、4 月(30 天)、5 月(31 天)、6 月(30 天)、7 月(31 天)、8 月(31 天)、9 月(30 天)、10 月(31 天)、11 月(30 天)和 12 月(31 天)。2 月在闰年中为 29 天,在平年中为 28 天。

每个 CultureInfo 都支持一组日历。Calendar 属性返回区域性的默认日历,OptionalCalendars 属性返回一个包含区域性所支持的所有日历的数组。若要更改 CultureInfo 所使用的日历,请将 CultureInfo.DateTimeFormatCalendar 属性设置为新的 Calendar

只有当在 DateTimeFormatInfo.Calendar 中选择了 GregorianCalendar 并且区域性使用“A.D.”作为纪元名称时,GetEra 才忽略缩写纪元名称中的标点;即“A.D.”等效于“AD”。

示例

下面的代码示例显示,只有当日历为公历并且区域性使用纪元名称“A.D.”时,DateTimeFormatInfo 才忽略纪元名称中的标点。

Imports System
Imports System.Globalization

Public Class SamplesGregorianCalendar

   Public Shared Sub Main()

      ' Creates strings with punctuation and without.
      Dim strADPunc As [String] = "A.D."
      Dim strADNoPunc As [String] = "AD"
      Dim strCEPunc As [String] = "C.E."
      Dim strCENoPunc As [String] = "CE"

      ' Calls DTFI.GetEra for each culture that uses GregorianCalendar as the default calendar.
      Console.WriteLine("            ----- AD -----  ----- CE -----")
      Console.WriteLine("CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR")
      Dim myCI As CultureInfo
      For Each myCI In  CultureInfo.GetCultures(CultureTypes.SpecificCultures)
         Console.Write("{0,-12}", myCI)
         Console.Write("{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra(strADPunc), myCI.DateTimeFormat.GetEra(strADNoPunc))
         Console.Write("{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra(strCEPunc), myCI.DateTimeFormat.GetEra(strCENoPunc))
         Console.Write("{0}", myCI.Calendar)
         Console.WriteLine()
      Next myCI

   End Sub 'Main 

End Class 'SamplesGregorianCalendar


'This code produces the following output.  This output has been cropped for brevity.
'
'            ----- AD -----  ----- CE -----
'CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR
'ar-SA       -1     -1       -1     -1       System.Globalization.HijriCalendar
'ar-IQ       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-EG       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-LY       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-DZ       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-MA       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-TN       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-OM       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-YE       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-SY       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-JO       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-LB       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-KW       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-AE       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-BH       1      1        -1     -1       System.Globalization.GregorianCalendar
'ar-QA       1      1        -1     -1       System.Globalization.GregorianCalendar
'bg-BG       1      1        -1     -1       System.Globalization.GregorianCalendar
'ca-ES       -1     -1       -1     -1       System.Globalization.GregorianCalendar
'zh-TW       -1     -1       -1     -1       System.Globalization.GregorianCalendar
'zh-CN       -1     -1       -1     -1       System.Globalization.GregorianCalendar
'zh-HK       -1     -1       -1     -1       System.Globalization.GregorianCalendar
'zh-SG       1      1        -1     -1       System.Globalization.GregorianCalendar
'zh-MO       1      1        -1     -1       System.Globalization.GregorianCalendar
'cs-CZ       -1     -1       -1     -1       System.Globalization.GregorianCalendar
'da-DK       1      1        -1     -1       System.Globalization.GregorianCalendar
using System;
using System.Globalization;


public class SamplesGregorianCalendar  {

   public static void Main()  {

      // Creates strings with punctuation and without.
      String strADPunc = "A.D.";
      String strADNoPunc = "AD";
      String strCEPunc = "C.E.";
      String strCENoPunc = "CE";

      // Calls DTFI.GetEra for each culture that uses GregorianCalendar as the default calendar.
      Console.WriteLine( "            ----- AD -----  ----- CE -----" );
      Console.WriteLine( "CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR" );
      foreach ( CultureInfo myCI in CultureInfo.GetCultures( CultureTypes.SpecificCultures ) )  {
         Console.Write( "{0,-12}", myCI );
         Console.Write( "{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra( strADPunc ), myCI.DateTimeFormat.GetEra( strADNoPunc ) );
         Console.Write( "{0,-7}{1,-9}", myCI.DateTimeFormat.GetEra( strCEPunc ), myCI.DateTimeFormat.GetEra( strCENoPunc ) );
         Console.Write( "{0}", myCI.Calendar );
         Console.WriteLine();
      }

   }

}

/*
This code produces the following output.  This output has been cropped for brevity.

            ----- AD -----  ----- CE -----
CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR
ar-SA       -1     -1       -1     -1       System.Globalization.HijriCalendar
ar-IQ       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-EG       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-LY       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-DZ       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-MA       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-TN       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-OM       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-YE       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-SY       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-JO       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-LB       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-KW       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-AE       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-BH       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-QA       1      1        -1     -1       System.Globalization.GregorianCalendar
bg-BG       1      1        -1     -1       System.Globalization.GregorianCalendar
ca-ES       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-TW       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-CN       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-HK       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-SG       1      1        -1     -1       System.Globalization.GregorianCalendar
zh-MO       1      1        -1     -1       System.Globalization.GregorianCalendar
cs-CZ       -1     -1       -1     -1       System.Globalization.GregorianCalendar
da-DK       1      1        -1     -1       System.Globalization.GregorianCalendar

*/
using namespace System;
using namespace System::Globalization;
using namespace System::Collections;
int main()
{
   
   // Creates strings with punctuation and without.
   String^ strADPunc = "A.D.";
   String^ strADNoPunc = "AD";
   String^ strCEPunc = "C.E.";
   String^ strCENoPunc = "CE";
   
   // Calls DTFI::GetEra for each culture that uses GregorianCalendar as the default calendar.
   Console::WriteLine( "            ----- AD -----  ----- CE -----" );
   Console::WriteLine( "CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR" );
   IEnumerator^ en = CultureInfo::GetCultures( CultureTypes::SpecificCultures )->GetEnumerator();
   while ( en->MoveNext() )
   {
      CultureInfo^ myCI = safe_cast<CultureInfo^>(en->Current);
      Console::Write( "{0, -12}", myCI );
      Console::Write( "{0,-7}{1,-9}", myCI->DateTimeFormat->GetEra( strADPunc ), myCI->DateTimeFormat->GetEra( strADNoPunc ) );
      Console::Write( "{0, -7}{1, -9}", myCI->DateTimeFormat->GetEra( strCEPunc ), myCI->DateTimeFormat->GetEra( strCENoPunc ) );
      Console::Write( "{0}", myCI->Calendar );
      Console::WriteLine();
   }
}

/*
This code produces the following output.  This output has been cropped for brevity.

            ----- AD -----  ----- CE -----
CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR
ar-SA       -1     -1       -1     -1       System.Globalization.HijriCalendar
ar-IQ       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-EG       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-LY       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-DZ       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-MA       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-TN       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-OM       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-YE       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-SY       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-JO       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-LB       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-KW       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-AE       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-BH       1      1        -1     -1       System.Globalization.GregorianCalendar
ar-QA       1      1        -1     -1       System.Globalization.GregorianCalendar
bg-BG       1      1        -1     -1       System.Globalization.GregorianCalendar
ca-ES       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-TW       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-CN       -1     -1       -1     -1       System.Globalization.GregorianCalendar
zh-HK       1      1        -1     -1       System.Globalization.GregorianCalendar
zh-SG       1      1        -1     -1       System.Globalization.GregorianCalendar
zh-MO       1      1        -1     -1       System.Globalization.GregorianCalendar
cs-CZ       -1     -1       -1     -1       System.Globalization.GregorianCalendar
da-DK       1      1        -1     -1       System.Globalization.GregorianCalendar

*/
import System.* ;
import System.Globalization.* ;

public class SamplesGregorianCalendar
{
    public static void main(String[] args)
    {
        // Creates strings with punctuation and without.
        String strADPunc = "A.D.";
        String strADNoPunc = "AD";
        String strCEPunc = "C.E.";
        String strCENoPunc = "CE";

        // Calls DTFI.GetEra for each culture that uses GregorianCalendar as 
        //the default calendar.
        Console.WriteLine("            ----- AD -----  ----- CE -----");
        Console.WriteLine("CULTURE PUNC NO PUNC  PUNC   NO PUNC  CALENDAR");
        for (int iCtr = 0; iCtr < (CultureInfo.GetCultures(
            CultureTypes.SpecificCultures).length); iCtr++) {

            CultureInfo myCI = CultureInfo.GetCultures( 
                CultureTypes.SpecificCultures)[iCtr];
            Console.Write("{0,-12}", myCI);
            Console.Write("{0,-7}{1,-9}", System.Convert.ToString(
                myCI.get_DateTimeFormat().GetEra(strADPunc)),System.Convert.
                ToString(myCI.get_DateTimeFormat().GetEra(strADNoPunc)));
            
            Console.Write("{0,-7}{1,-9}", System.Convert.ToString(
                myCI.get_DateTimeFormat().GetEra(strCEPunc)), 
                System.Convert.ToString(myCI.get_DateTimeFormat().
                GetEra(strCENoPunc)));
            
            Console.Write("{0}", myCI.get_Calendar());
            Console.WriteLine();
        }
    } //main
} //SamplesGregorianCalendar

/*
This code produces the following output.  This output has been cropped 
for brevity.

            ----- AD -----  ----- CE -----
CULTURE     PUNC   NO PUNC  PUNC   NO PUNC  CALENDAR
ar-SA       -1     -1       -1     -1       System.Globalization.HijriCalendar
ar-IQ       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-EG       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-LY       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-DZ       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-MA       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-TN       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-OM       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-YE       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-SY       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-JO       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-LB       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-KW       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-AE       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-BH       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ar-QA       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
bg-BG       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
ca-ES       -1     -1       -1     -1       System.Globalization.
                                            GregorianCalendar
zh-TW       -1     -1       -1     -1       System.Globalization.
                                            GregorianCalendar
zh-CN       -1     -1       -1     -1       System.Globalization.
                                            GregorianCalendar
zh-HK       -1     -1       -1     -1       System.Globalization.
                                            GregorianCalendar
zh-SG       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
zh-MO       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
cs-CZ       -1     -1       -1     -1       System.Globalization.
                                            GregorianCalendar
da-DK       1      1        -1     -1       System.Globalization.
                                            GregorianCalendar
*/

继承层次结构

System.Object
   System.Globalization.Calendar
    System.Globalization.GregorianCalendar

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

GregorianCalendar 成员
System.Globalization 命名空间
Calendar 类
CultureInfo.Calendar 属性
CultureInfo.OptionalCalendars 属性