Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get today's Jewish date in c#?

I have this code:

DateTime dtAnyDateHebrew = new DateTime(5767, 1, 1, new System.Globalization.HebrewCalendar());

how can I get the numeric Hebrew date of today?

Meaning:

For example I want to find out if a specific Hebrew month falls in this month, so I have to send the hebrew month to the function - with today's day of month and year, so that I'll be able to check if dtAnyDateHebrew is equal to Today, bigger than. etc.

finally I need to get - Today's hebrew day of month, Today's hebrew month, Today's hebrew year, as int (of course).

Can someone help me?

like image 237
Tal Avatar asked Jun 05 '11 20:06

Tal


People also ask

How do I put the Jewish date on my lock screen?

Go to Settings > Calendar > Alternative Calendars and select Hebrew. Presto.

What is the Hebrew date right now?

According to tradition, the Hebrew calendar started at the time of Creation, placed at 3761 BCE. The current (2021/2022) Hebrew year is 5782.

How do you calculate Jewish calendar?

1) Using gematria, add the letters of the Hebrew date together. 2) Add 1240 to the number you get. NOTE- The Jewish year begins in the middle of the Gregorian year, causing any Jewish year to correspond to two consecutive Gregorian years. The 1240 formula gives you the latter of the two years.

What is the difference between Jewish calendar and Gregorian calendar?

In contrast to the solar (Gregorian) calendar, the Jewish calendar follows the moon: a new moon signals a new month, and 29.5 days later, the next new moon – and its month – comes. (To make things “round” in the Jewish calendar, some months have 29 days and others 30 days.)


3 Answers

Well, I found what I need:

DateTime Today = DateTime.Today;

Calendar HebCal = new HebrewCalendar();
int curYear = HebCal.GetYear(Today);    //current numeric hebrew year
int curMonth = HebCal.GetMonth(Today);  //current numeric hebrew month

etc..

It's that simple.

Thanks to all of you.

like image 84
Tal Avatar answered Oct 18 '22 22:10

Tal


Use DateTime.Today and converted it using one of the following ex. methods:

/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using custom DateTime format string.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="format">A standard or custom date-time format string.</param>
public static string ToJewishDateString(this DateTime value, string format)
{
  var ci = CultureInfo.CreateSpecificCulture("he-IL");
  ci.DateTimeFormat.Calendar = new HebrewCalendar();      
  return value.ToString(format, ci);
}

/// <summary>
/// Converts a gregorian date to its hebrew date string representation,
/// using DateTime format options.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> value to convert.</param>
/// <param name="dayOfWeek">Specifies whether the return string should
/// include the day of week.</param>
public static string ToJewishDateString(this DateTime value, bool dayOfWeek)
{
  var format = dayOfWeek ? "D" : "d";
  return value.ToJewishDateString(format);
}
like image 40
Shimmy Weitzhandler Avatar answered Oct 18 '22 22:10

Shimmy Weitzhandler


This blog entry shows how.

public static string GetHebrewJewishDateString(DateTime anyDate, bool addDayOfWeek)  { 
    System.Text.StringBuilder hebrewFormatedString = new System.Text.StringBuilder(); 

    // Create the hebrew culture to use hebrew (Jewish) calendar 
    CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL"); 
    jewishCulture.DateTimeFormat.Calendar = new HebrewCalendar(); 

    #region Format the date into a Jewish format 

   if (addDayOfWeek) 
   { 
      // Day of the week in the format " " 
      hebrewFormatedString.Append(anyDate.ToString("dddd", jewishCulture) + " "); 
   } 

   // Day of the month in the format "'" 
   hebrewFormatedString.Append(anyDate.ToString("dd", jewishCulture) + " "); 

   // Month and year in the format " " 
   hebrewFormatedString.Append("" + anyDate.ToString("y", jewishCulture)); 
   #endregion 

   return hebrewFormatedString.ToString(); 
}
like image 36
Ernest Friedman-Hill Avatar answered Oct 18 '22 21:10

Ernest Friedman-Hill