C#将希伯来历日期转换为公历日期

时间:2020-02-01 22:11:59

标签: c# .net

我想将希伯来语日期(犹太)转换为公历日期; 我该怎么做? 我试过了,但是没用:

string birth = txtBearthDay.Text+" "+ txtBearthMonth.Text+" " + txtBearthYear.Text;
HebrewCalendar hc = new HebrewCalendar();
CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");

jewishCulture.DateTimeFormat.Calendar = hc;
dt = DateTime.Parse(birth,jewishCulture.DateTimeFormat);

2 个答案:

答案 0 :(得分:1)

尝试string date_in_oth_culture = dt.ToString(new CultureInfo("he-IL");。 希望对您有所帮助。


编辑:对不起,我误会了你的意思。您可以找到有关如何使用HebrewCalendar here的更多信息。
编辑2 : 不幸的是,文档中的代码都无法正常工作,在互联网上我也找不到任何内容。

一种解决方案可能是使用HebrewCalendar计算新日期,然后使用switch语句自己翻译它们。

HebrewCalendar hc = new HebrewCalendar();
CultureInfo culture = CultureInfo.CreateSpecificCulture("he-IL");
culture.DateTimeFormat.Calendar = hc;

DateTime hebrDate = hc.ToDateTime(year, month, day, hour, minute, second, millisecond, era); // Converts Hebrew date into Gregorian date


DateTime gregDate = new DateTime(2020, 2, 1); // Gregorian date

string hebrMonth;
switch(hc.GetMonth(gregDate))
{
  case 1:
    hebrMonth = "___";
    break;
  case 2:
    hebrMonth = "___";
    break;
  // And so on
}

string finalDate = hc.getDayOfMonth(gregDate) + " " + hebrMonth + " " + hc.getYear(gregDate) + " " + hc.getEra(gregDate);

我希望这会有所帮助。

答案 1 :(得分:1)

实际上非常简单:

new DateTime(5780, 5, 7, new HebrewCalendar())

这将返回具有Gregorian属性值(2020-02-02)的DateTime对象,因为DateTime的属性是使用Gregorian日历呈现的。如果要从日期时间中获取希伯来日历值,则必须显式查询HebrewCalendar类。

相关问题