Javascript 使用luxon检测时区缩写

Javascript 使用luxon检测时区缩写,javascript,datetime,timezone,momentjs,luxon,Javascript,Datetime,Timezone,Momentjs,Luxon,带有短时区缩写的时刻时区结果,例如 moment.tz([2012, 0], 'America/New_York').format('z'); // EST moment.tz([2012, 5], 'America/New_York').format('z'); // EDT 使用luxon有没有类似的方法可以实现这一点 我尝试了offsetNameShort,但结果是GMT+5:30,日期为“2020-05-23T13:30:00+05:30” 类似于DateTime.from

带有短时区缩写的时刻时区结果,例如

moment.tz([2012, 0], 'America/New_York').format('z');    // EST
moment.tz([2012, 5], 'America/New_York').format('z');    // EDT
使用luxon有没有类似的方法可以实现这一点

我尝试了offsetNameShort,但结果是
GMT+5:30
,日期为
“2020-05-23T13:30:00+05:30”

类似于
DateTime.fromISO(“2020-05-23T13:30:00+05:30”)。toFormat('z')
也不起作用

有没有办法从格式中删除
+5:30
时区?

查看。您希望缩写的命名偏移量为
ZZZZ

示例:

DateTime.fromObject({year: 2012, month: 1, zone: 'America/New_York'})
  .toFormat('ZZZZ') //=> "EST"

DateTime.fromObject({year: 2012, month: 6, zone: 'America/New_York'})
  .toFormat('ZZZZ') //=> "EDT"

DateTime.local()
  .toFormat('ZZZZ') //=> "PDT"  (on my computer)

DateTime.fromISO("2020-05-23T13:30:00+05:30", {zone: 'Asia/Kolkata', locale: 'en-IN'})
  .toFormat('ZZZZ') //=> "IST"
注意,在最后一个例子中,您还必须在中指定
en作为获取
IST
的区域设置。否则,您将获得
GMT+05:30
,除非系统区域设置已为
en IN
。这是因为Luxon依赖于浏览器的国际化API,而浏览器的国际化API又从中获取数据


在CLDR中,许多名称和缩写被指定为特定于给定的区域设置,而不是在全球范围内使用。在
Europe/London
获得
GMT+1
而不是
BST
时也会发生同样的情况,除非地区设置为
en GB
。(我个人不同意这一点,但这就是它目前的实现方式。)

这解释了为什么DateTImeFormat timeZoneName:“short”选项有时显示偏移量,而其他时间显示缩写。谢谢。:-)是的,CLDR数据的一个怪癖是,一些名字是在国家级别而不是语言级别分配的。不确定原因,但事实确实如此。@MattJohnson Pint
DateTime
offsetNameLong
offsetNameShort
作为实例属性,它们比格式标记更清晰