I want to display the date time (which I’ve placed on master page); in different language on the basis of current culture.
My javascript code on master:
<script type="text/javascript">
var t;
$(document).ready(function pageLoad() {
setTimeout('SetTime()', 1000);
});
function SetTime() {
var date = new Date();
date.format = 'MM.DD.YYYY';
$get('<%=lbl.ClientID %>').innerHTML = date.toLocaleDateString() + " : " + date.toLocaleTimeString();
setTimeout("SetTime()", 1000);
}
</script>
It always shows datetime string in English even if I set different culture say: french or any other.
I tried other way through code-behind file of master page:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
}
void Timer1_Tick(object sender, EventArgs e)
{
Label2.Text = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
UpdatePanel1.Update();
}
Here, I’m getting date string in different language on the basis of culture selected. But I don’t want to use Timer. Is there any way, I could achieve this without using timer. Thanks.
Try using this,
I am using “toString” function of Datejs datetime library in the above code.