我怎样才能在c#中获得今天的犹太约会?

Tal*_*Tal 12 c# date hebrew winforms

我有这个代码:

DateTime dtAnyDateHebrew = new DateTime(5767, 1, 1, new System.Globalization.HebrewCalendar());
Run Code Online (Sandbox Code Playgroud)

我如何获得今天的数字希伯来日期?

含义:

例如,我想知道本月特定的希伯来月份是否会下降,所以我必须将希伯来月份发送到函数 - 今天的月份和年份,以便我能够检查dtAnyDateHebrew是否相等到今天,比...更大.等等

最后我需要得到 - 今天的希伯来日,今天的希伯来月,今天的希伯来年,当然是int(当然).

有人能帮我吗?

Tal*_*Tal 9

好吧,我找到了我需要的东西:

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..
Run Code Online (Sandbox Code Playgroud)

就这么简单.

感谢大家.

  • 如果这解决了你的问题,你应该接受它作为答案. (3认同)

Shi*_*mmy 7

使用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);
}
Run Code Online (Sandbox Code Playgroud)

  • 惊人的!什科亚奇,西蒙! (3认同)

Ern*_*ill 3

这篇博客文章展示了如何操作。

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(); 
}
Run Code Online (Sandbox Code Playgroud)