Skip to content Skip to sidebar Skip to footer

Format Datetime With Moment.js To Show Timezone

I have problem showing timezone with moment.js. I tried with this code: var result = moment(someDate).format('MM/DD/YYYY HH:mm A Z'); and I get return, for example: 08/05/2015 06

Solution 1:

As described in the documentation:

Note: as of 1.6.0, the z/zz format tokens have been deprecated. Read more about it here.

The general problem is that time zone abbreviations are not available from the browser through a consistent API. In order to provide them, one has to have an external source of data.

You may want to look into using the moment-timezone addon. It provides time zone information, including abbreviations. You would have to know the specific time zone you are working with. For example:

moment.tz("2015-08-05T00:00:00+01:00", "Europe/London").format("MM/DD/YYYY hh:mm A z");
// "08/05/2015 12:00 AM BST"

Also, you shouldn't mix HH (hours of the 24-hour clock) with A (the 12-hour am/pm designator). Either use hh with A, or use HH without A.

Post a Comment for "Format Datetime With Moment.js To Show Timezone"