ASR
ASR

Reputation: 3549

How to get time zone of the client

I want to access timezoneId of client. For this I had tried different approaches to get timezoneId information. Like:

  1. calculating timezone from offset & daylight saving time,
  2. getting user location(i.e.longitude, latitude value) to know the timezoneId of that location

I am getting the result but exact results (for all timezones) For example two countries having same offset value then I am unable to locate exact one based on their system timezone setting; like:for Arizona and Mountain Time(US & Canada) both having offset value is UTC-7.00

Right now for both the value it is giving "MST" i.e. Mountain Standard Time as timezoneId. But I want what ever I will configure means if I will select Arizona then it will return Arizona and if I will select Mountain Time(US & Canada) then it will give its corresponding timezoneId.

Can you help me to get exact timezoneId ?

Thanks,

Upvotes: 2

Views: 297

Answers (2)

Honey Goyal
Honey Goyal

Reputation: 445

Try this,

var d = new Date();
var n = d.toString();
//This will give you like MST, according to browser's time
var timeZone = (n.split("(")[1]).replace(")", ""); 

Upvotes: 1

TheLittleHawk
TheLittleHawk

Reputation: 628

There is small lib jsTimezoneDetect. It should give you America/Arizona, etc.

http://pellepim.bitbucket.org/jstz/

Upvotes: 1

Related Questions