如何格式化我的时间显示以显示夏令时标签?

时间:2017-12-07 21:09:50

标签: javascript time ecmascript-6 timezone momentjs

我的时间就像这样显示

moment(date).tz(TimeZone).format('h:mm a z')

1:02 p.m. EST

我想要它说什么

1:02 p.m. EDT

如何将其更改为夏令时

2 个答案:

答案 0 :(得分:1)

每当遇到诸如日期或时间等问题时,如果您想获得定制结果,则有助于将代码重构为某种日期类。幸运的是,dateJS一个处理日期和时间的javascript库可以帮助你。

关于显示夏令时,本例给出了您想要的内容。

getTimezoneAbbreviation

Date.getTimezoneAbbreviation ( Number timezoneOffset, Boolean isDayLightSavingsTime ) : String

Returns a culture-specific timezone abbreviation based on a given offset and a boolean indicating whether daylight savings time is in effect.

Parameters
{Number timezoneOffset} The year.
{Boolean isDayLightSavingsTime} Whether the date instance is observing Daylight Saving Time (Summer Time)
Return Value
{String} The timezone abbreviation

Example
var today = Date.today(); Date.getTimezoneAbbreviation(today.getTimezoneOffset, today.isDayLightSavingsTime()); // "UTC", "GMT", "EST", "PDT", etc.

答案 1 :(得分:0)

我暂时无法做到这一点

jun.tz('America/New_York').format('ha z'); // 8am EDT
dec.tz('America/New_York').format('ha z'); // 7am EST
在冬天,我总是认为