UmAlQuraCalendar.GetYear Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Updated: October 2010

Calculates the year of a date represented by a specified DateTime.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides Function GetYear ( _
    time As DateTime _
) As Integer
public override int GetYear(
    DateTime time
)

Parameters

Return Value

Type: System.Int32
An integer that represents the year specified by the time parameter.

Exceptions

Exception Condition
ArgumentOutOfRangeException

time is outside the range supported by this calendar.

Examples

The following example displays the date ranges supported by the UmAlQuraCalendar class in both the Gregorian and Um Al Qura calendars. The GetYear method is used to retrieve the year of the minimum and maximum supported dates in the Um Al Qura calendar if it is not the current culture's current calendar.

Imports System.Globalization

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim cal As New UmAlQuraCalendar()
      Dim minDate As Date = cal.MinSupportedDateTime
      Dim maxDate As Date = cal.MaxSupportedDateTime

      outputBlock.Text &= "Range of the Um Al Qura calendar:" & vbCrLf
      ' Is UmAlQuraCalendar the current calendar?
      If DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("UmAlQura") Then
         Dim greg As New GregorianCalendar()
         outputBlock.Text += String.Format("   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) & vbCrLf
         outputBlock.Text += String.Format("   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) & vbCrLf
         ' Is Gregorian the current calendar?
      ElseIf DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("Gregorian") Then
         outputBlock.Text += String.Format("   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)) & vbCrLf
         outputBlock.Text += String.Format("   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)) & vbCrLf
         ' Display ranges if some other calendar is current.
      Else
         Dim greg As New GregorianCalendar()
         outputBlock.Text += String.Format("   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)) & vbCrLf
         outputBlock.Text += String.Format("   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)) & vbCrLf
      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
using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Calendar cal = new UmAlQuraCalendar();
      DateTime minDate = cal.MinSupportedDateTime;
      DateTime maxDate = cal.MaxSupportedDateTime;

      outputBlock.Text += "Range of the Um Al Qura calendar:" + "\n";
      // Is UmAlQuraCalendar the current calendar?
      if (DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("UmAlQura"))
      {
         Calendar greg = new GregorianCalendar();
         outputBlock.Text += String.Format("   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) + "\n";
         outputBlock.Text += String.Format("   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) + "\n";
      }
      // Is Gregorian the current calendar?
      else if (DateTimeFormatInfo.CurrentInfo.Calendar.ToString().Contains("Gregorian"))
      {
         outputBlock.Text += String.Format("   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)) + "\n";
         outputBlock.Text += String.Format("   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)) + "\n";
      }
      // Display ranges if some other calendar is current.
      else
      {
         GregorianCalendar greg = new GregorianCalendar();
         outputBlock.Text += String.Format("   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)) + "\n";
         outputBlock.Text += String.Format("   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)) + "\n";
      }
   }
}
// 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

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.

Change History

Date

History

Reason

October 2010

Replaced the example.

Customer feedback.