1

I have created an application that depends on the timezone (set on the OS) of the client to render a display.

However, if the client incorrectly set his timezone on his pc, my display breaks.

My question is: How to i get the appropriate timezone of the client, based on where he is right now?

I understood that there are a couple of solutions: I could do this by using google API and then know the location of the client.However, this would require asking the client permission before accessing his location. I also read that you could use IP address of the client but this is unreliable. Finally, I could just ask the client.

Is there any other way to do this dynamically? Any help is appreciated

PS: I understand that the question is broad and my question would simply require a list of possibilities. No definite answer.

mushood badulla
  • 1,043
  • 1
  • 12
  • 19
  • Honestly, if you don't trust the user to set his time zone correctly on his computer, then none of the other methods you describe (which are perfectly valid) would work either. In the end, the user can always choose to pretend to be elsewhere, via one mechanism or another. Besides, there are plenty of folks who *choose* to set their computer to another time zone for valid business reasons, or to remain fixed to their home time zone when travelling. It really is a personal preference, not something you can enforce. – Matt Johnson-Pint Mar 09 '17 at 21:16
  • Thats true. I've tried to look everywhere for a solution and could not find a completely reliable one. However, at the the end of the day, I should just be giving the users what they are asking for, that is the information according to the timezone THEY have set, conciously/uncounciously. – mushood badulla Mar 11 '17 at 05:40

1 Answers1

0

Javascript new Date().toString(); would give you all the information you need about the time at the user and the timezone (if set properly). You can then send it to your server and do what you intend to.

var split = new Date().toString().split(" ");
var timeZoneFormatted = split[split.length - 2] + " " + split[split.length - 1]; //outputs "GMT+1100 (AEDT)"

No permission needed for this one. Just sends it back to your server as you want and work with it.

Javascript code from here: Getting the client's timezone in JavaScript

Community
  • 1
  • 1
EddyTheDove
  • 12,979
  • 2
  • 37
  • 45