Tuesday, October 11, 2011

Browser timezone

In Page Load add the following.

Page.ClientScript.RegisterStartupScript(this.GetType(), "onLoad",
"script language='javascript' type='text/javascript'>GetTimeZoneOffset();script");

//hdnLocalEndTime is the Hidden variable, which will hold the timezoneoffset.
function GetTimeZoneOffset()
var txtLocalEndTime=document.getElementById('hdnLocalEndTime');
var date = new Date()
var gmtHours = - date.getTimezoneOffset()/60;

//Servermethod to calculate time in Browser timezone

string strEndDateTime="it should be the date and time in string format";
DateTime dt;
dt = Convert.ToDateTime(strEndDateTime);
txtEndTime.Text = Convert.ToString(dt.ToUniversalTime().AddHours(Convert.ToDouble(hdnLocalEndTime.Value)));
//txtEndTime.Text will display the time in local time zone

No comments: