gpt4 book ai didi

c# - 如何在 C# 中从希伯来日历中获取英文月份名称

转载 作者:太空狗 更新时间:2023-10-29 23:22:08 25 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

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

全局.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"
};

实用程序.cs

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com