Can't set automatically TimeZone in TimePicker

94 views Asked by At

Using TimePiker I want to set timezone:

$('#timeStart').timepicker({
                showTimezone: true,
                timeFormat: "hh:mm TT",
                timezoneList: 
              [
                { 'value': '-720', 'label': '(GMT-12:00) International Date Line West' },
                { 'value': '-660', 'label': '(GMT-11:00) Midway Island, Samoa' }
                   ....
                { 'value': '+840', 'label': '(GMT+14:00) Time in Samoa' }
              ]
        });

timepiker is initialized and zones is added in selector but selected value is the first from list is not detected if I set manually option timezone: '+840' it work

why timezone is not detect automatically?

2

There are 2 answers

0
Alex On BEST ANSWER

I found solution,instead of

{ 'value': '-720', 'label': '(GMT-12:00) International Date Line West' }

Is need to use

{ value: -720, label: '(GMT-12:00) International Date Line West' }
4
monxas On

I'm not familiar with that time picker, but if you can manually select it, by using

new Date().getTimezoneOffset();

You can probably make a workaround it.

diff = new Date().getTimezoneOffset();

timediff = diff/-60;


currentTimezone = (timediff > 0)? "+" : "-";
currentTimezone = (Math.abs(timediff) >= 9)? currentTimezone + Math.abs(timediff): currentTimezone +"0"+ Math.abs(timediff);
currentTimezone += "00";
console.log(currentTimezone)