我尝试了这样的东西:
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
等)。
是否有办法在国际上显示用户所在时区的缩写名称?因此,它将显示BST
,而不是伦敦的GMT+1
?
https://stackoverflow.com/questions/52672237
复制相似问题