Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
2.71/5 (3 votes)
See more:
Hello All,
I have a asp.net dropdown and I am binding all timezones to it.
C#
ddlTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();//binding time zone list in drop down list
ddlTimeZone.DataValueField = "Id";
ddlTimeZone.DataTextField = "DisplayName";
ddlTimeZone.DataBind();


What I want is when a user from Australia visit my page, I want to by default select his timezone in dropdown and if user is from canada, his timezone should be selected.

I appreciate any help, suggestion, code, link..

Thanks in advance
Posted

 
Share this answer
 
v4
Comments
Herbisaurus 19-Aug-13 10:06am    
*****
salah9 20-Aug-13 0:18am    
The first link provided wont work, by using the code given i will get result in minutes not in timezone, if i got minutes i need to convert that minutes to hours and then match with the list which c# provides.
for example if the result is -330(which divied by 60 will give 5.5) 5.5 is the hour difference.
Now there are 3 countries which have the time difference of 5.5, i cant get accurate from which of the 3 country user is from..
salah9 20-Aug-13 0:19am    
And second link doesnt provide timezone completely.. it just give country/city name
Mike Meinz 20-Aug-13 8:42am    
See "Automatic Timezone Detection Using JavaScript" in revised Solution 1.
Note that this is not a C# question since you need to detect the timezone on the client side. This means that you probably need to use Javascript to do the job.

See: Auto detect a time zone with JavaScript[^]
Or have a look at this W3Schools' tutorial[^]


You can add values to the DropDownList to match the result given by the JS and then in JS autoselect the right item.


Cheers,
Edo
 
Share this answer
 
v4
Comments
Herbisaurus 19-Aug-13 10:06am    
*****
salah9 20-Aug-13 0:19am    
??
salah9 20-Aug-13 0:20am    
first link wont provide user timezone, it provide user city name
Joezer BH 20-Aug-13 6:29am    
The getTimezoneOffset() provides the Time Zone Offset

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900