views:

32

answers:

2

I have a web app hosted with GoDaddy (so the web server is in Arizona - Mountain Time). My users are mostly in Central Time Zone, but I could have some from other time zones.

I have a web page with a databound dropDownList using TimeZoneInfo, and I want to set the selected value of this dropDownList to whatever timeZone the user is in. Here's my code currently:

protected void Page_Load(object sender, EventArgs e)
{
    DropDownListTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();
    DropDownListTimeZone.DataBind();

    TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
    DropDownListTimeZone.SelectedValue = cst.DisplayName;
}

It's ok, but I want it to be smarter for those users who aren't in CST. I was hoping there is some way to grab the user's TimeZoneInfo from something like Page.Request.?? but I can't figure it out.

Is there an easy solution to this?

A: 

I think this would require a bit of javascript; since it's running on the user's browser, it could pick up whatever time zone the computer is set to and set the selected item in the dropdown accordingly.

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

pjabbott
A: 

I was hoping there is some way to grab the user's TimeZoneInfo from something like Page.Request

There is not. You can guess from the client side using JavaScript—see this question—but it is just a guess.

There's no interface to get definitive client timezone information from a browser. So you'll definitely want to provide the user-selected setting, using the JS guess as a default value.

bobince