Как я могу получить сегодняшнее еврейское свидание в c #? - PullRequest
12 голосов
/ 06 июня 2011

У меня есть этот код:

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

как узнать числовую дату на иврите сегодня?

Значение:

Например, я хочу узнать,в этом месяце выпадает определенный ивритский месяц, поэтому мне нужно отправить ивритский месяц в функцию - с сегодняшним днем ​​месяца и года, чтобы я мог проверить, равен ли dtAnyDateHebrew значению Today, больше чем.и т. д.

наконец-то мне нужно получить - сегодняшний еврейский день месяца, сегодняшний еврейский месяц, сегодняшний еврейский год, как int (конечно).

Может ли кто-нибудь мне помочь?

Ответы [ 3 ]

9 голосов
/ 09 июня 2011

Ну, я нашел то, что мне нужно:

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..

Это так просто.

Спасибо всем вам.

6 голосов
/ 19 января 2012

Используйте DateTime.Today и конвертируйте его, используя один из следующих примеров.методы:

/// <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);
}
3 голосов
/ 06 июня 2011

Эта запись в блоге показывает, как.

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(); 
}
...