我想显示带有文化“he-IL”和希伯来日历的日期,但我没有成功。我得到以下信息:
预期: יום שלישי ט"ז אייר תשע"ב
实际: יום שלישי 08 שבט 2012
只有一部分日期被正确显示,任何想法为什么会发生这种情况?这是一个使用 C# 的示例(它正确显示日期)和另一个使用 Javascript 的示例(它没有正确显示日期):
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent" >
<script type="text/javascript">
function foo() {
var d = new Date();
var p = document.getElementById("txtHebrewDateJS");
p.value = d.localeFormat(Sys.CultureInfo.CurrentCulture.dateTimeFormat.LongDatePattern);
}
</script>
<asp:Label runat="server" Text="Hebrew calendar, culture he-IL, using code behind" />
<asp:TextBox runat="server" ID="txtHebrewDate" />
<br />
<asp:Label ID="Label1" runat="server" Text="Hebrew calendar, culture he-IL, using asp net ajax" />
<asp:TextBox runat="server" ClientIDMode="Static" ID="txtHebrewDateJS" />
<br />
<asp:Button runat="server" Text="load hebrew date" onclientclick="foo();" />
后面的代码:
using System;
using System.Globalization;
using System.Threading;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
txtHebrewDate.Text = DateTime.Now.ToString(Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern);
}
protected override void InitializeCulture() {
var c = new System.Globalization.CultureInfo("he-IL");
c.DateTimeFormat.Calendar = new HebrewCalendar();
Thread.CurrentThread.CurrentCulture = c;
Thread.CurrentThread.CurrentUICulture = c;
base.InitializeCulture();
}
}