无法在 TimePicker 中自动设置 TimeZone

Can't set automatically TimeZone in TimePicker

使用TimePiker我想设置时区:

$('#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 已初始化并在选择器中添加了区域但未检测到所选值是列表中的第一个 如果我手动设置选项时区:'+840' 它工作

为什么没有自动检测时区?

我不熟悉那个时间选择器,但是如果你可以手动 select 它,使用

new Date().getTimezoneOffset();

您或许可以解决它。

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)

我找到了解决方案,而不是

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

需要使用

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