I want to show the date with the he-IL culture and the Jewish calendar, but I have not had any success. I get the following:
Expected: ΧΧΧ Χ©ΧΧΧ©Χ Χ "Χ ΧΧΧΧ¨ ΧͺΧ©Χ’" Χ
Actual: ΧΧΧ Χ©ΧΧΧ©Χ 08 Χ©ΧΧ 2012
Only one part of the date is correctly calculated, any ideas why this is happening? Here is one example of using C # (it displays the date correctly) and the other with Javascript (it does not display the date correctly):
<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();" />
Code behind:
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();
}
}
source
share