0

My requirement is , i need to convert the time zone value to offset value for ex.. Asia/Dubai to +4 .. consider am intializing date in js.

var currentDate = new Date();

and it is possible to set the time zone and get the offset..

currentDate.setTimezone("Asia/Dubai");
var offsetValue=currentDate.getTimezoneOffset();

alert('offsetValue---'+offsetValue);

its not working.. page error at set time zone.. is there any other way to get the offet value? Need to consider DST too..

A Programmer
  • 368
  • 4
  • 7
  • 26

2 Answers2

1

The Date object doesn't know a setTimezone method. If you want to set a Date to the 'Asia/Dubai' timezone, this could be a way:

var regionalDate = new Date;
regionalDate.setHours(regionalDate.getUTCHours()+4); //=> set to UTC+4
KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • hi my query is i need to convert asia/dubai to +4..please read the first line of the description – A Programmer Apr 25 '12 at 08:43
  • 1
    Well, you'll have to think of something yourself for such a conversion. There's no miraculous native timezoneconverter in javascript. It could be as easy as assigning a value to a variable called 'Dubai' (`var Dubai = 4`), or creating an object for different timezones (`var zones = {Asia: { Dubai:4, Brunei:8, Mumbai: 5.5 }, Europe: {Amsterdam: {summer:2; winter:1} }`) etc. It's up to you. See also: http://www.timeanddate.com/worldclock/ – KooiInc Apr 25 '12 at 10:17
  • @mnp: check http://stackoverflow.com/questions/11887934/check-if-daylight-saving-time-is-in-effect-and-if-it-is-for-how-many-hours – KooiInc Apr 18 '13 at 13:39
1

This is not a valid jquery statement

currentDate.setTimezone("Asia/Dubai");

just remove this line and you'll get the timezone offset.

Shahbaz Chishty
  • 482
  • 1
  • 4
  • 9