How to get client current date and time in asp.net?

f4had

New Member
I have a hidden field in my master page. And I set the current date and time as a value in that "hiddenfield" using Javascript. I am unable to get this hidden field value in any other page's page load method.Here is my code.\[code\]HiddenField hdnCurrentDate = (HiddenField)this.Master.FindControl("hdnCurrentDate"); ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "var CurrentDate = new Date(); $('#" + hdnCurrentDate.ClientID + "').val(CurrentDate);alert($('#ctl00_hdnCurrentDate').val());", true);\[/code\]I have defined Hiddenfield in aspx page like\[code\]<asp:HiddenField ID="hdnCurrentDate" runat="server" />\[/code\]I got the alert of "hdnCurrentDate" is undefined. This is because I wrote the code in page load in not post back method.Here is the other way what I have implemented.I have used ConvertTimeBySystemTimeZoneId in code behind. Here is the code for the same.\[code\]DateTime ClientDateTime = DateTime.Now; DateTime _localTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(ClientDateTime, "Arab Standard Time"); return _localTime;\[/code\]I didn't get destination time zone ID instead of "Arab standard Time". If I will get it, my problem will be solved.Is there any other way to get the current date time in any of my page. I don't want to use Session and cookies.Thanks in advance.
 
Back
Top