GregorianCalendar 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示公历。
public ref class GregorianCalendar : System::Globalization::Calendar
public class GregorianCalendar : System.Globalization.Calendar
[System.Serializable]
public class GregorianCalendar : System.Globalization.Calendar
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class GregorianCalendar : System.Globalization.Calendar
type GregorianCalendar = class
inherit Calendar
[<System.Serializable>]
type GregorianCalendar = class
inherit Calendar
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type GregorianCalendar = class
inherit Calendar
Public Class GregorianCalendar
Inherits Calendar
- 继承
- 属性
示例
下面的代码示例显示, DateTimeFormatInfo 仅当日历为公历且区域性使用纪元名称“A.D.”时,才忽略纪元名称中的标点符号。
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
*/
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
*/
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
End Class
'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
注解
公历可识别两个纪元:B.C.或 B.C.E.,以及 A.D. 或 C.E.类的 GregorianCalendar 此实现仅识别当前纪元 (A.D. 或 C.E.) 。
注意
有关在.NET Framework中使用 GregorianCalendar 类和其他日历类的信息,请参阅使用日历。
公历中的闰年定义为可均匀地被 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 天。
重要
默认情况下,所有 DateTime 和 DateTimeOffset 值都表示公历中的日期和时间。
公历是作为朱利安历 (的替代而开发的,该历由 JulianCalendar 类) 代表,于1582年10月15日首次在少数文化中引入。 处理区域性采用公历之前的历史日期时,如果原始日历在.NET Framework中可用,则应使用原始日历。 例如,丹麦在 2 月 19 日从朱利安历更改为公历, (在朱利安历) 或 3 月 1 日 (公历) 1700。 在这种情况下,对于采用公历之前的日期,应使用朱利安历。 但请注意,没有区域性为 JulianCalendar 类提供内部支持。 必须将 JulianCalendar 类用作独立日历。 有关详细信息,请参阅使用日历。
以下示例说明,在 1700 年 2 月 18 日,这是丹麦正式使用朱利安历的最后一天,比公历 1700 年 3 月 1 日早一天。
using System;
using System.Globalization;
using System.Threading;
public class Example
{
public static void Main()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
JulianCalendar jc = new JulianCalendar();
DateTime lastDate = new DateTime(1700, 2, 18, jc);
Console.WriteLine("Last date (Gregorian): {0:d}", lastDate);
Console.WriteLine("Last date (Julian): {0}-{1}-{2}\n", jc.GetDayOfMonth(lastDate),
jc.GetMonth(lastDate), jc.GetYear(lastDate));
DateTime firstDate = lastDate.AddDays(1);
Console.WriteLine("First date (Gregorian): {0:d}", firstDate);
Console.WriteLine("First date (Julian): {0}-{1}-{2}", jc.GetDayOfMonth(firstDate),
jc.GetMonth(firstDate), jc.GetYear(firstDate));
}
}
// The example displays the following output:
// Last date (Gregorian): 28-02-1700
// Last date (Julian): 18-2-1700
//
// First date (Gregorian): 01-03-1700
// First date (Julian): 19-2-1700
Imports System.Globalization
Imports System.Threading
Module Example
Public Sub Main()
Thread.CurrentThread.CurrentCulture = New CultureInfo("da-DK")
Dim jc As New JulianCalendar()
Dim lastDate As New DateTime(1700, 2, 18, jc)
Console.WriteLine("Last date (Gregorian): {0:d}", lastDate)
Console.WriteLine("Last date (Julian): {0}-{1}-{2}", jc.GetDayOfMonth(lastDate),
jc.GetMonth(lastDate), jc.GetYear(lastDate))
Console.WriteLine()
Dim firstDate As DateTime = lastDate.AddDays(1)
Console.WriteLine("First date (Gregorian): {0:d}", firstDate)
Console.WriteLine("First date (Julian): {0}-{1}-{2}", jc.GetDayOfMonth(firstDate),
jc.GetMonth(firstDate), jc.GetYear(firstDate))
End Sub
End Module
' The example displays the following output:
' Last date (Gregorian): 28-02-1700
' Last date (Julian): 18-2-1700
'
' First date (Gregorian): 01-03-1700
' First date (Julian): 19-2-1700
每个都 CultureInfo 支持一组日历。 属性 Calendar 返回区域性的默认日历,属性 OptionalCalendars 返回包含区域性支持的所有日历的数组。 若要更改 使用的 CultureInfo日历,应用程序可以将 属性设置为 Calendar 新的 Calendar。
GetEra 仅当 GregorianCalendar 在 中选择 DateTimeFormatInfo.Calendar 了 并且区域性使用“A.D.”作为纪元名称(即“A.D.”)等效于“AD”时,才忽略缩写纪元名称中的标点符号。
构造函数
GregorianCalendar() |
使用默认的 GregorianCalendar 值初始化 GregorianCalendarTypes 类的新实例。 |
GregorianCalendar(GregorianCalendarTypes) |
使用指定的 GregorianCalendarTypes 值初始化 GregorianCalendar 类的新实例。 |
字段
ADEra |
表示当前纪元。 此字段为常数。 |
CurrentEra |
表示当前日历的当前纪元。 字段的值为 0。 (继承自 Calendar) |
属性
AlgorithmType |
获取一个值,该值指示当前日历是阳历、阴历还是二者的组合。 |
AlgorithmType |
获取一个值,该值指示当前日历是阳历、阴历还是二者的组合。 (继承自 Calendar) |
CalendarType |
获取或设置 GregorianCalendarTypes 值,该值指示当前 GregorianCalendar 的语言版本。 |
DaysInYearBeforeMinSupportedYear |
获取 MinSupportedDateTime 属性指定的年份之前的年中天数。 (继承自 Calendar) |
Eras |
获取 GregorianCalendar 中的纪元列表。 |
IsReadOnly |
获取一个值,该值指示此 Calendar 对象是否为只读。 (继承自 Calendar) |
MaxSupportedDateTime |
获取 GregorianCalendar 类型支持的最晚日期和时间。 |
MaxSupportedDateTime |
获取此 Calendar 对象支持的最晚日期和时间。 (继承自 Calendar) |
MinSupportedDateTime |
获取 GregorianCalendar 类型支持的最早日期和时间。 |
MinSupportedDateTime |
获取此 Calendar 对象支持的最早日期和时间。 (继承自 Calendar) |
TwoDigitYearMax |
获取或设置可以用两位数年份表示的 100 年范围内的最后一年。 |