0

I need to get client side timezone using JavaScript. I am using below code.

new Date().toString().split('(')[1].slice(0, -1)

But it returns timezone daylightname, and I need id.

For example, client side timezone as set as (UTC-05:00) Eastern Time (US & Canada) and I need to get output as Eastern Standard Time. But I am getting Eastern Daylight Time as output.

Can I do this without any additional plugin requirements?

halfer
  • 18,701
  • 13
  • 79
  • 158
  • Perhaps this can help you: https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript – Gen4ik Jul 23 '17 at 08:08
  • You may want to look at [How can I get the timezone name in JavaScript?](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions). – Amin NAIRI Jul 23 '17 at 08:09
  • Possible duplicate: https://stackoverflow.com/questions/18246547/get-name-of-time-zone – Thang Pham Jul 23 '17 at 08:10
  • Those are not exactly matches with my requirement. Most of comments code including new date() method which will return daylight name not standard name of timezone – Rahini Krishna Jul 23 '17 at 08:30

2 Answers2

0

Try the following

var objdatetime = new Date();
var timezone = objdatetime.toTimeString();
var tzstr = timezone.split("(");
var timezoneid = tzstr[1].toString().replace(")","");
alert(timezoneid);
Osama
  • 2,629
  • 1
  • 8
  • 14
0

How about this?

new Date().toString().split('(')[1].slice(0, -1).replace('Daylight', 'Standard')
Brad Pitcher
  • 1,587
  • 15
  • 21