Search code examples
javascriptdatetimemomentjsmoment-timezone

Is Zone abbreviation using moment-zone library a dynamic


I am using moment timezone library to show the zone abbreviation after the timestamp. I am using the following snippet to show the zone abbreviation of New York, USA

 var timeZone = moment.tz.guess();
    const zoneName = moment.tz(timeZone).zoneName();
    return moment().tz("America/New_York").zoneName();

This returns me the Zone abbreviation EDT. My question is: when winter will come will it automatically return EST?


Solution

  • Yes, it will.

    var jun = moment("2014-06-01T12:00:00Z");
    var dec = moment("2014-12-01T12:00:00Z");
    
    jun.tz('America/New_York').format('ha z');     // 8am EDT
    dec.tz('America/New_York').format('ha z');     // 7am EST
    

    Source