Bewerken

Delen via


HebrewCalendar Class

Definition

Represents the Hebrew calendar.

public ref class HebrewCalendar : System::Globalization::Calendar
public class HebrewCalendar : System.Globalization.Calendar
[System.Serializable]
public class HebrewCalendar : System.Globalization.Calendar
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class HebrewCalendar : System.Globalization.Calendar
type HebrewCalendar = class
    inherit Calendar
[<System.Serializable>]
type HebrewCalendar = class
    inherit Calendar
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type HebrewCalendar = class
    inherit Calendar
Public Class HebrewCalendar
Inherits Calendar
Inheritance
HebrewCalendar
Attributes

Examples

The following example creates a file that contains the date ranges supported by the HebrewCalendar class, and displays the number of days in each month of the year 5772.

using System;
using System.Globalization;
using System.IO;
using System.Threading;

public class Example
{
   public static void Main()
   {
      StreamWriter output = new StreamWriter("HebrewCalendarInfo.txt");

      // Make the Hebrew Calendar the current calendar and
      // Hebrew (Israel) the current thread culture.
      HebrewCalendar hc = new HebrewCalendar();
      CultureInfo culture = CultureInfo.CreateSpecificCulture("he-IL");
      culture.DateTimeFormat.Calendar = hc;
      Thread.CurrentThread.CurrentCulture = culture;

      output.WriteLine("{0} Information:\n",
                       GetCalendarName(culture.DateTimeFormat.Calendar));

      // Get the calendar range expressed in both Hebrew calendar and
      // Gregorian calendar dates.
      output.WriteLine("Start Date: {0} ", hc.MinSupportedDateTime);
      culture.DateTimeFormat.Calendar = culture.Calendar;
      output.WriteLine("            ({0} Gregorian)\n",
                       hc.MinSupportedDateTime);

      culture.DateTimeFormat.Calendar = hc;
      output.WriteLine("End Date: {0} ", hc.MaxSupportedDateTime);
      culture.DateTimeFormat.Calendar = culture.Calendar;
      output.WriteLine("          ({0} Gregorian)\n",
                       hc.MaxSupportedDateTime);

      culture.DateTimeFormat.Calendar = hc;

      // Get the year in the Hebrew calendar that corresponds to 1/1/2012
      // and display information about it.
      DateTime startOfYear = new DateTime(2012, 1, 1);
      output.WriteLine("Days in the Year {0}: {1}\n",
                       hc.GetYear(startOfYear),
                       hc.GetDaysInYear(hc.GetYear(startOfYear)));

      output.WriteLine("Days in Each Month of {0}:\n", hc.GetYear(startOfYear));
      output.WriteLine("Month       Days       Month Name");
      // Change start of year to first day of first month
      startOfYear = hc.ToDateTime(hc.GetYear(startOfYear), 1, 1, 0, 0, 0, 0);
      DateTime startOfMonth = startOfYear;
      for (int ctr = 1; ctr <= hc.GetMonthsInYear(hc.GetYear(startOfYear)); ctr++) {
         output.Write(" {0,2}", ctr);
         output.WriteLine("{0,12}{1,15:MMM}",
                          hc.GetDaysInMonth(hc.GetYear(startOfMonth), hc.GetMonth(startOfMonth)),
                          startOfMonth);
         startOfMonth = hc.AddMonths(startOfMonth, 1);
      }

      output.Close();
   }

   private static string GetCalendarName(Calendar cal)
   {
      return cal.ToString().Replace("System.Globalization.", "").Replace("Cal", " Cal");
   }
}
// The example displays the following output:
//       Hebrew Calendar Information:
//
//       Start Date: ז// טבת שמ"ג 00:00:00
//                   (01/01/1583 00:00:00 Gregorian)
//
//       End Date: כ"ט אלול תתקצ"ט 23:59:59
//                 (29/09/2239 23:59:59 Gregorian)
//
//       Days in the Year 5772: 354
//
//       Days in Each Month of 5772:
//
//       Month       Days       Month Name
//         1          30           תשרי
//         2          29           חשון
//         3          30           כסלו
//         4          29            טבת
//         5          30            שבט
//         6          29            אדר
//         7          30           ניסן
//         8          29           אייר
//         9          30           סיון
//        10          29           תמוז
//        11          30             אב
//        12          29           אלול
Imports System.Globalization
Imports System.IO
Imports System.Threading

Module Example
   Public Sub Main()
      Dim output As New StreamWriter("HebrewCalendarInfo.txt")
      
      ' Make the Hebrew Calendar the current calendar and
      ' Hebrew (Israel) the current thread culture.
      Dim hc As New HebrewCalendar()
      Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("he-IL")
      culture.DateTimeFormat.Calendar = hc
      Thread.CurrentThread.CurrentCulture = culture
      
      output.WriteLine("{0} Information:", 
                       GetCalendarName(culture.DateTimeFormat.Calendar))
      output.WriteLine()
      
      ' Get the calendar range expressed in both Hebrew calendar and
      ' Gregorian calendar dates.
      output.WriteLine("Start Date: {0} ", 
                       hc.MinSupportedDateTime)  
      culture.DateTimeFormat.Calendar = culture.Calendar
      output.WriteLine("            ({0} Gregorian)", 
                       hc.MinSupportedDateTime)
      output.WriteLine()
      
      culture.DateTimeFormat.Calendar = hc
      output.WriteLine("End Date: {0} ", 
                   hc.MaxSupportedDateTime)
      culture.DateTimeFormat.Calendar = culture.Calendar
      output.WriteLine("          ({0} Gregorian)", 
                       hc.MaxSupportedDateTime)  
      output.WriteLine()
      
      culture.DateTimeFormat.Calendar = hc
      
      ' Get the year in the Hebrew calendar that corresponds to 1/1/2012
      ' and display information about it.
      Dim startOfYear As Date = #1/1/2012#
      output.WriteLine("Days in the Year {0}: {1}", 
                       hc.GetYear(startOfYear), 
                       hc.GetDaysInYear(hc.GetYear(startOfYear)))
      output.WriteLine()
      
      output.WriteLine("Days in Each Month of {0}:", hc.GetYear(startOfYear))
      output.WriteLine()
      output.WriteLine("Month       Days       Month Name")
      ' Change start of year to first day of first month 
      startOfYear = hc.ToDateTime(hc.GetYear(startOfYear), 1, 1, 0, 0, 0, 0)
      Dim startOfMonth As Date = startOfYear
      For ctr As Integer = 1 To hc.GetMonthsInYear(hc.GetYear(startOfYear)) 
         output.Write(" {0,2}", ctr)
         output.WriteLine("{0,12}{1,15:MMM}", 
                          hc.GetDaysInMonth(hc.GetYear(startOfMonth), hc.GetMonth(startOfMonth)),
                          startOfMonth)  
         startOfMonth = hc.AddMonths(startOfMonth, 1)                 
      Next 
                                     
      output.Close()          
   End Sub
   
   Private Function GetCalendarName(cal As Calendar) As String
      Return cal.ToString().Replace("System.Globalization.", "").Replace("Cal", " Cal")
   End Function
End Module
' The example displays the following output:
'       Hebrew Calendar Information:
'       
'       Start Date: ז' טבת שמ"ג 00:00:00 
'                   (01/01/1583 00:00:00 Gregorian)
'       
'       End Date: כ"ט אלול תתקצ"ט 23:59:59 
'                 (29/09/2239 23:59:59 Gregorian)
'       
'       Days in the Year 5772: 354
'       
'       Days in Each Month of 5772:
'       
'       Month       Days       Month Name
'         1          30           תשרי
'         2          29           חשון
'         3          30           כסלו
'         4          29            טבת
'         5          30            שבט
'         6          29            אדר
'         7          30           ניסן
'         8          29           אייר
'         9          30           סיון
'        10          29           תמוז
'        11          30             אב
'        12          29           אלול

The example instantiates a HebrewCalendar object and makes it the current calendar of a Hebrew (Israel) CultureInfo object. It then makes Hebrew (Israel) the current culture. This causes the common language runtime to interpret all dates and times in relation to the Hebrew calendar.

Remarks

The Hebrew calendar recognizes two eras: B.C.E. (before the common era) and A.M. (Latin "Anno Mundi", which means "the year of the world"). This implementation of the HebrewCalendar class recognizes only the current era (A.M.) and the Hebrew years 5343 to 5999 (1583 to 2239 in the Gregorian calendar).

Note

For information about using the HebrewCalendar class and the other calendar classes in the .NET Framework, see Working with Calendars.

In every 19-year cycle that ends with a year that is evenly divisible by 19, the 3rd, 6th, 8th, 11th, 14th, 17th, and 19th years are leap years. A common year can have from 353 to 355 days, depending on the placement of Jewish holidays. A leap year can have from 383 to 385 days.

The Hebrew calendar has 12 months during common years and 13 months during leap years:

GetMonth value (common year) GetMonth value (leap year) Month Days in common years Days in leap years
1 1 תשרי (Tishrei) 30 30
2 2 חשון (Cheshvan) 29/30 29/30
3 3 כסלו (Kislev) 29/30 29/30
4 4 טבת (Tevet) 29 29
5 5 שבט (Shevat) 30 30
6 - אדר (Adar) 29 -
- 6 אדר א (Adar Alef) - 30
- 7 אדר ב (Adar Beit) - 29
7 8 ניסן (Nissan) 30 30
8 9 אייר (Iyar) 29 29
9 10 סיון (Sivan) 30 30
10 11 תמוז (Tamuz) 29 29
11 12 אב (Av) 30 30
12 13 אלול (Elul) 29 29

The days in Cheshvan and Kislev vary depending on the placement of Jewish holidays. During leap years, Adar is replaced by Adar Alef with 30 days and Adar Beit with 29 days. Adar Alef is considered the leap month. The last day of Adar Alef and all the days in Adar Beit are considered leap days; that is, the IsLeapDay method returns true for these days.

The date January 1, 2001 A.D. in the Gregorian calendar is equivalent to the sixth day of Tevet in the year 5761 A.M. in the Hebrew calendar.

Each CultureInfo supports a set of calendars. The Calendar property returns the default calendar for the culture, and the OptionalCalendars property returns an array containing all the calendars supported by the culture. To change the calendar used by a CultureInfo, the application should set the Calendar property of CultureInfo.DateTimeFormat to a new Calendar.

Constructors

HebrewCalendar()

Initializes a new instance of the HebrewCalendar class.

Fields

CurrentEra

Represents the current era of the current calendar. The value of this field is 0.

(Inherited from Calendar)
HebrewEra

Represents the current era. This field is constant.

Properties

AlgorithmType

Gets a value that indicates whether the current calendar is solar-based, lunar-based, or a combination of both.

AlgorithmType

Gets a value indicating whether the current calendar is solar-based, lunar-based, or a combination of both.

(Inherited from Calendar)
DaysInYearBeforeMinSupportedYear

Gets the number of days in the year that precedes the year that is specified by the MinSupportedDateTime property.

(Inherited from Calendar)
Eras

Gets the list of eras in the HebrewCalendar.

IsReadOnly

Gets a value indicating whether this Calendar object is read-only.

(Inherited from Calendar)
MaxSupportedDateTime

Gets the latest date and time supported by the HebrewCalendar type.

MaxSupportedDateTime

Gets the latest date and time supported by this Calendar object.

(Inherited from Calendar)
MinSupportedDateTime

Gets the earliest date and time supported by the HebrewCalendar type.

MinSupportedDateTime

Gets the earliest date and time supported by this Calendar object.

(Inherited from Calendar)
TwoDigitYearMax

Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.

Methods

AddDays(DateTime, Int32)

Returns a DateTime that is the specified number of days away from the specified DateTime.

(Inherited from Calendar)
AddHours(DateTime, Int32)

Returns a DateTime that is the specified number of hours away from the specified DateTime.

(Inherited from Calendar)
AddMilliseconds(DateTime, Double)

Returns a DateTime that is the specified number of milliseconds away from the specified DateTime.

(Inherited from Calendar)
AddMinutes(DateTime, Int32)

Returns a DateTime that is the specified number of minutes away from the specified DateTime.

(Inherited from Calendar)
AddMonths(DateTime, Int32)

Returns a DateTime that is the specified number of months away from the specified DateTime.

AddSeconds(DateTime, Int32)

Returns a DateTime that is the specified number of seconds away from the specified DateTime.

(Inherited from Calendar)
AddWeeks(DateTime, Int32)

Returns a DateTime that is the specified number of weeks away from the specified DateTime.

(Inherited from Calendar)
AddYears(DateTime, Int32)

Returns a DateTime that is the specified number of years away from the specified DateTime.

Clone()

Creates a new object that is a copy of the current Calendar object.

(Inherited from Calendar)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDayOfMonth(DateTime)

Returns the day of the month in the specified DateTime.

GetDayOfWeek(DateTime)

Returns the day of the week in the specified DateTime.

GetDayOfYear(DateTime)

Returns the day of the year in the specified DateTime.

GetDaysInMonth(Int32, Int32, Int32)

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

GetDaysInMonth(Int32, Int32)

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

(Inherited from Calendar)
GetDaysInYear(Int32, Int32)

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

GetDaysInYear(Int32)

Returns the number of days in the specified year of the current era.

(Inherited from Calendar)
GetEra(DateTime)

Returns the era in the specified DateTime.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetHour(DateTime)

Returns the hours value in the specified DateTime.

(Inherited from Calendar)
GetLeapMonth(Int32, Int32)

Calculates the leap month for a specified year and era.

GetLeapMonth(Int32, Int32)

Calculates the leap month for a specified year and era.

(Inherited from Calendar)
GetLeapMonth(Int32)

Calculates the leap month for a specified year.

(Inherited from Calendar)
GetMilliseconds(DateTime)

Returns the milliseconds value in the specified DateTime.

(Inherited from Calendar)
GetMinute(DateTime)

Returns the minutes value in the specified DateTime.

(Inherited from Calendar)
GetMonth(DateTime)

Returns the month in the specified DateTime.

GetMonthsInYear(Int32, Int32)

Returns the number of months in the specified year in the specified era.

GetMonthsInYear(Int32)

Returns the number of months in the specified year in the current era.

(Inherited from Calendar)
GetSecond(DateTime)

Returns the seconds value in the specified DateTime.

(Inherited from Calendar)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek)

Returns the week of the year that includes the date in the specified DateTime value.

(Inherited from Calendar)
GetYear(DateTime)

Returns the year in the specified DateTime value.

IsLeapDay(Int32, Int32, Int32, Int32)

Determines whether the specified date in the specified era is a leap day.

IsLeapDay(Int32, Int32, Int32)

Determines whether the specified date in the current era is a leap day.

(Inherited from Calendar)
IsLeapMonth(Int32, Int32, Int32)

Determines whether the specified month in the specified year in the specified era is a leap month.

IsLeapMonth(Int32, Int32)

Determines whether the specified month in the specified year in the current era is a leap month.

(Inherited from Calendar)
IsLeapYear(Int32, Int32)

Determines whether the specified year in the specified era is a leap year.

IsLeapYear(Int32)

Determines whether the specified year in the current era is a leap year.

(Inherited from Calendar)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)

Returns a DateTime that is set to the specified date and time in the specified era.

ToDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

Returns a DateTime that is set to the specified date and time in the current era.

(Inherited from Calendar)
ToFourDigitYear(Int32)

Converts the specified year to a 4-digit year by using the TwoDigitYearMax property to determine the appropriate century.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also