Here are some source code to pass DateTime JavaScript value to ASP.NET in C#. It is used to get client side date and time. It is useful for those who need to display client date and time instead of hosting server date and time.

Put these codes at HTML

<input type=”hidden” id=”hdClient” runat=”server” />

Put these codes at ASP.NET code behind

At Page_Load
Page.RegisterClientScriptBlock(“1″,
“<script type=’text/javascript’>
function goforit()
{var now = new Date();
var offset = now.getTimezoneOffset();
document.forms[0].hdClient.value = -offset}
</script>”);

ClientScriptManager manager = Page.ClientScript;
manager.RegisterStartupScript(this.GetType(), “CallSomething”, “goforit();”, true);

And…

Label1.Text =
DateTime.Now.ToUniversalTime().AddMinutes(double.Parse(Request.Form["hdClient"])).ToString();

Hope this will help. :D

Related Entries