Fetching contributors…
Cannot retrieve contributors at this time
83 lines (66 sloc) 2.99 KB
title signature
Formatting Additions"Z z"); // -08:00 PST; // PST; // PST

In addition to including the +00:00 formatting information, Moment Timezone also includes information for the abbreviated time zone name.[2012, 0], 'America/New_York').format('z');    // EST[2012, 5], 'America/New_York').format('z');    // EDT[2012, 0], 'America/Los_Angeles').format('z'); // PST[2012, 5], 'America/Los_Angeles').format('z'); // PDT

Note that these abbreviations may change depending on the time zone offset. This helps to distinguish offsets between places that may or may not use DST.

// Denver observes DST[2012, 0], 'America/Denver').format('Z z');  // -07:00 MST[2012, 5], 'America/Denver').format('Z z');  // -06:00 MDT
// Phoenix does not observe DST[2012, 0], 'America/Phoenix').format('Z z'); // -07:00 MST[2012, 5], 'America/Phoenix').format('Z z'); // -07:00 MST

Note also that these abbreviations are not globally unique. Below, you can see that both United States Central Standard Time and China Standard Time have the same abbreviation.'2016-01-01', 'America/Chicago').format('z');    // CST'2016-01-01', 'Asia/Shanghai').format('z');      // CST

You can also use moment#zoneAbbr to get the zone abbreviation. This is what moment.js uses when formatting the z token.[2012, 0], 'America/New_York').zoneAbbr(); // EST[2012, 5], 'America/New_York').zoneAbbr(); // EDT

Moment.js also provides a hook for the long form time zone name. Because these strings are generally localized, Moment Timezone does not provide any long names for zones.

To provide long form names, you can override moment.fn.zoneName and use the zz token.

var abbrs = {
    EST : 'Eastern Standard Time',
    EDT : 'Eastern Daylight Time',
    CST : 'Central Standard Time',
    CDT : 'Central Daylight Time',
    MST : 'Mountain Standard Time',
    MDT : 'Mountain Daylight Time',
    PST : 'Pacific Standard Time',
    PDT : 'Pacific Daylight Time',

moment.fn.zoneName = function () {
    var abbr = this.zoneAbbr();
    return abbrs[abbr] || abbr;
};[2012, 0], 'America/New_York').format('zz');    // Eastern Standard Time[2012, 5], 'America/New_York').format('zz');    // Eastern Daylight Time[2012, 0], 'America/Los_Angeles').format('zz'); // Pacific Standard Time[2012, 5], 'America/Los_Angeles').format('zz'); // Pacific Daylight Time

Please note that the z formatting token will not always show the abbreviated time zone name, instead, will show the time offsets for each region.'America/Los_Angeles').format('z')  // "PDT"     (abbreviation)'Asia/Magadan').format('z')         // "+11"     (3-char offset)'Asia/Colombo').format('z')         // "+0530"   (5-char offset)