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..

4
  • 2
    What's your opinion regarding daylight savings time?
    – Cameron
    Commented Apr 25, 2012 at 4:48
  • use timezone-js. this will make your work simpler ..
    – Pranav
    Commented Apr 25, 2012 at 5:03
  • can u share me that? timezone.js Commented Apr 25, 2012 at 5:15
  • 2
    Best link on SO for TimeZone and daylight saving time:- stackoverflow.com/questions/2532729/…
    – Pranav
    Commented Apr 25, 2012 at 5:25

2 Answers 2

1

This is not a valid jquery statement

currentDate.setTimezone("Asia/Dubai");

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

1
  • 1
    hi my query is i need to convert asia/dubai to +4... please read the first line of the description Commented Apr 25, 2012 at 8:43
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
3
  • hi my query is i need to convert asia/dubai to +4..please read the first line of the description Commented Apr 25, 2012 at 8: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: timeanddate.com/worldclock
    – KooiInc
    Commented Apr 25, 2012 at 10:17
  • @mnp: check stackoverflow.com/questions/11887934/…
    – KooiInc
    Commented Apr 18, 2013 at 13:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.