我正在尝试使用C#以英语输出希伯来语日历日期。以下以希伯来语输出日期:

    var ci = System.Globalization.CultureInfo.CreateSpecificCulture("he-IL");
    ci.DateTimeFormat.Calendar = new System.Globalization.HebrewCalendar();
    Response.Write(DateTime.Today.ToString("MMM d, yyyy", ci));
    Response.Write(DateTime.Today.ToString("d-M-y", ci));


כסלו כ"ו, תשע"ה
כ"ו-ג'-תשע"ה

时间为2014年12月18日。将CultureInfo更改为“en-US”会引发“对于给定文化而言无效的日历”。错误。我试图得到
26 Kislev 5775


26-09-5775

最佳答案

我不知道如何设置leap年的月份名称数组或天数的数组,以使它们呈现为英文数字而不是希伯来字母。我的解决方案是:

Globals.cs

    public static string[] HebrewMonthNames =
    {
      "Tishrei",
      "Cheshvan",
      "Kislev",
      "Tevet",
      "Shevat",
      "Adar",
      "Nissan",
      "Iyar",
      "Sivan",
      "Tamuz",
      "Av",
      "Elul"
    };

    public static string[] HebrewMonthNamesLeapYear =
    {
      "Tishrei",
      "Cheshvan",
      "Kislev",
      "Tevet",
      "Shevat",
      "Adar I",
      "Adar II",
      "Nissan",
      "Iyar",
      "Sivan",
      "Tamuz",
      "Av",
      "Elul"
    };

实用工具
public string FormatHebrewDate(DateTime dtGregorian)
{
                System.Globalization.HebrewCalendar hCal = new System.Globalization.HebrewCalendar();
                string sDate = hCal.GetDayOfMonth(dtGregorian).ToString() + " ";
                if (hCal.IsLeapYear(hCal.GetYear(dtGregorian)))
                {
                    sDate += Globals.HebrewMonthNamesLeapYear[hCal.GetMonth(dtGregorian) - 1];
                }
                else
                {
                    sDate += Globals.HebrewMonthNames[hCal.GetMonth(dtGregorian) - 1];
                }
                sDate += " " + hCal.GetYear(dtGregorian).ToString();
                return sDate;
}

关于c# - 如何从C#中的希伯来语日历中获取英语月份的名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27541762/

10-12 12:36