Format datetime with moment.js to show timezone

前端 未结 1 845
天命终不由人
天命终不由人 2020-12-21 08:44

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\");
相关标签:
1条回答
  • 2020-12-21 09:25

    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.

    0 讨论(0)
提交回复
热议问题