I am using ASP.NET Webforms to get the data of client. till now I figured out the IP address of client and the city & country of the client. I am trying to find a way of how to retrieve the time zone by using its IP Address or country name or city name. I have googled and couldn't find any appropriate answer as everyone talks about injecting javascript to get timezone. My question is: Is there any way to find timezone of the client? If so then how?`
-
Please don't randomly turn words into bold or code for no reason - it makes it really hard to read. – Jon Skeet Apr 18 '16 at 18:45
-
@Kritner i have read many articles stackoverflow, they all ask to inject javascript, but i want to work on c#. either it asks to get timezone from any link or something like that! – Jamshaid K. Apr 18 '16 at 18:48
2 Answers
It is not possible to do this in a reliable way purely with C#. The HTTP spec does not provide any hints of the client's time zone.
You can guess at a client's time zone by using IP geolocation, and there are many free and commercial services that provide time zone information. However there is only a limited degree of accuracy with such an approach.
Even with JavaScript, the current solutions can still only guess the client's time zone. There are improvements happening for this with in the ECMAScript Intl API, but not all browsers fully implement that yet. See more here.
Ultimately, if you need to know the time zone of the client from your back end code, the best thing to do is to ask the user. Provide a time zone picker somewhere in your application.
You may also find this related answer useful.

- 1
- 1

- 230,703
- 74
- 448
- 575
-
yeah, i saw those articles but they were very old threads, so i thought to ask it again wondering maybe there is a way programmers have discovered now :( – Jamshaid K. Apr 18 '16 at 20:28
-
is there any way we can get time from internet by providing the city and country ? @Matt Johnson – Jamshaid K. Apr 18 '16 at 20:28
-
I'm sure there are many services that provide such lookups. Try http://ip-api.com. See this answer also: http://stackoverflow.com/a/16086964/634824. Note that in both cases, you're getting an IANA time zone ID. To use with .NET, you need [Noda Time](http://nodatime.org). – Matt Johnson-Pint Apr 18 '16 at 20:56
-
i have got timezone, i did this by using javascript, i couldn't use c#, now can i get time from the timezone i got? @Matt Johnson – Jamshaid K. Apr 20 '16 at 21:23
-
As I said - You need [Noda Time](http://nodatime.org) if you want to do it in C#. If you want to stay in JavaScript, use [moment.js](http://momentjs.com) with the time zone addon. – Matt Johnson-Pint Apr 20 '16 at 23:46
Have you tried using the TimeZoneInfo Class It represents any time zone in the world.
https://msdn.microsoft.com/en-us/library/system.timezoneinfo(v=vs.110).aspx

- 9
- 2
-
-
1This won't help with detecting the client's time zone in a web app. – Matt Johnson-Pint Apr 18 '16 at 19:07
-
@Lakiel Wade it didn't helped as my time is 1:21 a.m and it returns 3:21 p.m – Jamshaid K. Apr 18 '16 at 20:21