UmAlQuraCalendar.GetYear(DateTime) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
计算由指定 DateTime 表示的日期所在的年份。
public:
override int GetYear(DateTime time);
public override int GetYear (DateTime time);
override this.GetYear : DateTime -> int
Public Overrides Function GetYear (time As DateTime) As Integer
参数
- time
- DateTime
要读取的日期值。 UmAlQuraCalendar 类仅支持从 1900/04/30 00.00.00(公历日期)到 2077/11/16 23:59:59(公历日期)的日期。
返回
一个整数,表示由 time
参数指定的年份。
例外
time
超出了此日历支持的范围。
示例
以下示例在公历和 Um Al Qura 日历中显示 类支持的 UmAlQuraCalendar 日期范围。 方法 GetYear 用于检索 Um Al Qura 日历中支持的最小和最大日期的年份(如果不是当前区域性的当前日历)。
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
Calendar cal = new UmAlQuraCalendar();
DateTime minDate = cal.MinSupportedDateTime;
DateTime maxDate = cal.MaxSupportedDateTime;
Console.WriteLine("Range of the Um Al Qura calendar:");
// Is UmAlQuraCalendar the current calendar?
if (DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("UmAlQura")) {
Calendar greg = new GregorianCalendar();
Console.WriteLine(" Minimum: {0:d2}/{1:d2}/{2:d4} {3:HH:mm:ss} Gregorian, {3:MM/dd/yyyy HH:mm:ss} Um Al Qura",
greg.GetMonth(minDate), greg.GetDayOfMonth(minDate),
greg.GetYear(minDate), minDate);
Console.WriteLine(" Maximum: {0:d2}/{1:d2}/{2:d4} {3:HH:mm:ss} Gregorian, {3:MM/dd/yyyy HH:mm:ss} Um Al Qura",
greg.GetMonth(maxDate), greg.GetDayOfMonth(maxDate),
greg.GetYear(maxDate), maxDate);
}
// Is Gregorian the current calendar?
else if (DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("Gregorian")) {
Console.WriteLine(" Minimum: {0:d} {0:HH:mm:ss} Gregorian, {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} Um Al Qura",
minDate, cal.GetMonth(minDate), cal.GetDayOfMonth(minDate),
cal.GetYear(minDate));
Console.WriteLine(" Maximum: {0:d} {0:HH:mm:ss} Gregorian, {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} Um Al Qura",
maxDate, cal.GetMonth(maxDate), cal.GetDayOfMonth(maxDate),
cal.GetYear(maxDate));
}
// Display ranges if some other calendar is current.
else {
GregorianCalendar greg = new GregorianCalendar();
Console.WriteLine(" Minimum: {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} " +
"Gregorian, {4:d2}/{5:d2}/{6:d4} {0:HH:mm:ss} Um Al Qura",
minDate, greg.GetMonth(minDate), greg.GetDayOfMonth(minDate),
greg.GetYear(minDate), cal.GetMonth(minDate), cal.GetDayOfMonth(minDate),
cal.GetYear(minDate));
Console.WriteLine(" Maximum: {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} " +
"Gregorian, {4:d2}/{5:d2}/{6:d4} {0:HH:mm:ss} Um Al Qura",
maxDate, greg.GetMonth(maxDate), greg.GetDayOfMonth(maxDate),
greg.GetYear(maxDate), cal.GetMonth(maxDate), cal.GetDayOfMonth(maxDate),
cal.GetYear(maxDate));
}
}
}
// The example displays output similar to the following:
// Range of the Um Al Qura calendar:
// Minimum: 4/30/1900 00:00:00 Gregorian, 01/01/1318 00:00:00 Um Al Qura
// Maximum: 5/13/2029 23:59:59 Gregorian, 12/29/1450 23:59:59 Um Al Qura
Imports System.Globalization
Module Example
Public Sub Main()
Dim cal As New UmAlQuraCalendar()
Dim minDate As Date = cal.MinSupportedDateTime
Dim maxDate As Date = cal.MaxSupportedDateTime
Console.WriteLine("Range of the Um Al Qura calendar:")
' Is UmAlQuraCalendar the current calendar?
If DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("UmAlQura") Then
Dim greg As New GregorianCalendar()
Console.WriteLine(" Minimum: {0:d2}/{1:d2}/{2:d4} {3:HH:mm:ss} Gregorian, {3:MM/dd/yyyy HH:mm:ss} Um Al Qura",
greg.GetMonth(minDate), greg.GetDayOfMonth(minDate),
greg.GetYear(minDate), minDate)
Console.WriteLine(" Maximum: {0:d2}/{1:d2}/{2:d4} {3:HH:mm:ss} Gregorian, {3:MM/dd/yyyy HH:mm:ss} Um Al Qura",
greg.GetMonth(maxDate), greg.GetDayOfMonth(maxDate),
greg.GetYear(maxDate), maxDate)
' Is Gregorian the current calendar?
ElseIf DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("Gregorian") Then
Console.WriteLine(" Minimum: {0:d} {0:HH:mm:ss} Gregorian, {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} Um Al Qura",
minDate, cal.GetMonth(minDate), cal.GetDayOfMonth(minDate),
cal.GetYear(minDate))
Console.WriteLine(" Maximum: {0:d} {0:HH:mm:ss} Gregorian, {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} Um Al Qura",
maxDate, cal.GetMonth(maxDate), cal.GetDayOfMonth(maxDate),
cal.GetYear(maxDate))
' Display ranges if some other calendar is current.
Else
Dim greg As New GregorianCalendar()
Console.WriteLine(" Minimum: {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} " +
"Gregorian, {4:d2}/{5:d2}/{6:d4} {0:HH:mm:ss} Um Al Qura",
minDate, greg.GetMonth(minDate), greg.GetDayOfMonth(minDate),
greg.GetYear(minDate), cal.GetMonth(minDate), cal.GetDayOfMonth(minDate),
cal.GetYear(minDate))
Console.WriteLine(" Maximum: {1:d2}/{2:d2}/{3:d4} {0:HH:mm:ss} " +
"Gregorian, {4:d2}/{5:d2}/{6:d4} {0:HH:mm:ss} Um Al Qura",
maxDate, greg.GetMonth(maxDate), greg.GetDayOfMonth(maxDate),
greg.GetYear(maxDate), cal.GetMonth(maxDate), cal.GetDayOfMonth(maxDate),
cal.GetYear(maxDate))
End If
End Sub
End Module
' The example displays output similar to the following:
' Range of the Um Al Qura calendar:
' Minimum: 4/30/1900 00:00:00 Gregorian, 01/01/1318 00:00:00 Um Al Qura
' Maximum: 5/13/2029 23:59:59 Gregorian, 12/29/1450 23:59:59 Um Al Qura