Share via


PersianCalendar.GetDaysInMonth Method (Int32, Int32, Int32)

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

Returns the number of days in the specified month of the specified year and era.

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

Syntax

'Declaration
Public Overrides Function GetDaysInMonth ( _
    year As Integer, _
    month As Integer, _
    era As Integer _
) As Integer
public override int GetDaysInMonth(
    int year,
    int month,
    int era
)

Parameters

  • year
    Type: System.Int32
    An integer from 1 through 9378 that represents the year.
  • month
    Type: System.Int32
    An integer that represents the month, and ranges from 1 through 12 if year is not 9378, or 1 through 10 if year is 9378.
  • era
    Type: System.Int32
    An integer from 0 through 1 that represents the era.

Return Value

Type: System.Int32
The number of days in the specified month of the specified year and era.

Exceptions

Exception Condition
ArgumentOutOfRangeException

year, month, or era is outside the range supported by this calendar.

Examples

The following example uses the GetDaysInMonth method.

using System;
using System.Globalization;

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock) 
    {
        //--------------------------------------------------------------------------------
        // Get today's date.
        //--------------------------------------------------------------------------------
      outputBlock.Text += "\n................. Today ...........................\n";
      PersianCalendar jc = new PersianCalendar();
      DateTime thisDate = DateTime.Now;

        // Display the current date using the Gregorian and Persian calendars.
      outputBlock.Text += "Today is:\n";
      outputBlock.Text += String.Format("   {0:dddd}, {0} in the Gregorian calendar.\n", thisDate);
      outputBlock.Text += String.Format("   {0}, {1}/{2}/{3} {4}:{5}:{6} in the Persian calendar.\n", 
                                        jc.GetDayOfWeek(thisDate), 
                                        jc.GetMonth(thisDate), 
                                        jc.GetDayOfMonth(thisDate), 
                                        jc.GetYear(thisDate), 
                                        jc.GetHour(thisDate), 
                                        jc.GetMinute(thisDate), 
                                        jc.GetSecond(thisDate));
        //--------------------------------------------------------------------------------
        // Fields
        //--------------------------------------------------------------------------------
      outputBlock.Text += "\n............... Fields .............................\n";
      outputBlock.Text += String.Format("PersianEra = {0}\n", PersianCalendar.PersianEra);
        //--------------------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------------------
      outputBlock.Text += "\n............... Properties .........................\n";
      outputBlock.Text += "Eras:";
      foreach (int era in jc.Eras)
      {
         outputBlock.Text += String.Format(" era = {0}\n", era);
      }
        //--------------------------------------------------------------------------------
      outputBlock.Text += "\nGregorian Date Range Supported by the Persian Calendar:\n";
      outputBlock.Text += String.Format("   From {0:G}\n", jc.MinSupportedDateTime);
      outputBlock.Text += String.Format("   To {0:G}\n", jc.MaxSupportedDateTime);
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("\nTwoDigitYearMax = {0}\n", jc.TwoDigitYearMax);
        //--------------------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------------------
      outputBlock.Text += "\n............ Selected Methods .......................\n";

        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("GetDayOfYear: day = {0}\n", jc.GetDayOfYear(thisDate));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("GetDaysInMonth: days = {0}\n", 
                                        jc.GetDaysInMonth( thisDate.Year, thisDate.Month, 
                                        PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("GetDaysInYear: days = {0}\n", 
                        jc.GetDaysInYear(thisDate.Year, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("GetLeapMonth: leap month (if any) = {0}\n", 
                        jc.GetLeapMonth(thisDate.Year, PersianCalendar.PersianEra));
        //-------------------------------------------------------------
      outputBlock.Text += String.Format("GetMonthsInYear: months in a year = {0}\n", 
                        jc.GetMonthsInYear(thisDate.Year, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("IsLeapDay: This is a leap day = {0}\n", 
                        jc.IsLeapDay(thisDate.Year, thisDate.Month, thisDate.Day, 
                        PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("IsLeapMonth: This is a leap month = {0}\n", 
                        jc.IsLeapMonth(thisDate.Year, thisDate.Month, 
                        PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
      outputBlock.Text += String.Format("IsLeapYear: 1370 is a leap year = {0}\n", 
                        jc.IsLeapYear(1370, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------

        // Get the 4-digit year for a year whose last two digits are 99. The 4-digit year 
        // depends on the current value of the TwoDigitYearMax property.

      outputBlock.Text += "ToFourDigitYear:\n";
      outputBlock.Text += String.Format("  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}\n", 
                         jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
      jc.TwoDigitYearMax = thisDate.Year;
      outputBlock.Text += String.Format("  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}\n", 
                        jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
    }
}
/*
The example produces the following results:

................. Today ...........................

Today is Wednesday, 6/14/2006 11:31:13 AM

............... Fields .............................

PersianEra = 1

............... Properties .........................

Eras: era = 1
MaxSupportedDateTime = 12/31/9999 11:59:59 PM
MinSupportedDateTime = 3/21/0622 12:00:00 AM
TwoDigitYearMax = 1410

................ Methods ...........................

AddMonths: thisDate + 6 months = 12/15/2006 11:31:13 AM
           thisDate - 6 months = 12/15/2005 11:31:13 AM
AddYears:  thisDate + 5 years =  6/14/2011 11:31:13 AM
           thisDate - 3 years =  6/14/2003 11:31:13 AM
GetDayOfMonth: month = 24
GetDayOfWeek: day = Wednesday
GetDayOfYear: day = 86
GetDaysInMonth: days = 31
GetDaysInYear: days = 366
GetEra: era = 1
GetLeapMonth: leap month (if any) = 0
GetMonth: month = 3
GetMonthsInYear: months in a year = 12
GetYear: year = 1385
IsLeapDay: This is a leap day = False
IsLeapMonth: This is a leap month = False
IsLeapYear: 1370 is a leap year = True
ToDateTime:
  Gregorian calendar: 6/10/2006 8:30:15 PM
  Persian calendar:   3/20/1385 8:30:15 PM
ToFourDigitYear:
  If TwoDigitYearMax = 1410, ToFourDigitYear(99) = 1399
  If TwoDigitYearMax = 2006, ToFourDigitYear(99) = 1999

*/

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.