如何显示用户的缩写名称';JavaScript中的时区(不是GMT偏移量)?

如何显示用户的缩写名称';JavaScript中的时区(不是GMT偏移量)?,javascript,timezone,Javascript,Timezone,我试过这样的方法: function set_local_time(utcSeconds) { var d = new Date(0); // The 0 sets the date to the epoch d.setUTCSeconds(utcSeconds); //update date object with utcSeconds return d.toLocaleTimeString() + ', ' + d.toLocaleDateString() + ' '

我试过这样的方法:

function set_local_time(utcSeconds) {
    var d = new Date(0); // The 0 sets the date to the epoch
    d.setUTCSeconds(utcSeconds); //update date object with utcSeconds
    return d.toLocaleTimeString() + ', ' + d.toLocaleDateString() + ' ' + d.toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2] //time, date timezone 
}
这会占用时间并将其转换为用户的本地时间。它在美国境内工作正常(显示
PDT
EDT
,等等),但在美国境外,它只显示GMT偏移量(例如
GMT+1
GMT+8
,等等)


有没有办法在国际上显示用户时区的缩写名称?因此,它将显示伦敦的
GMT+1
,而不是
BST

您无法直接从
日期对象获取此信息,但您可以从如下界面获取此信息:

让tz=Intl.DateTimeFormat().resolvedOptions().timeZone;
控制台日志(tz)