Format Moment.js am/pm to include periods/dots

前端 未结 4 1088
再見小時候
再見小時候 2021-01-25 13:56

I\'m running into a small formatting issue with moment\'s a input.

a/A will return AM/am PM/pm but is there a way to format this to include periods?

<
4条回答
  •  感情败类
    2021-01-25 14:13

    Following moment docs you can have the following:

    moment.updateLocale('en', {
      meridiem: function (hour, minute, isLowercase) {
        if( hour >= 12 )
          return isLowercase ? 'p.m.' : 'P.M.';
        else
          return isLowercase ? 'a.m.' : 'A.M.';
      }
    });
    console.log(moment().hour(1).format('HH:mm a'));
    console.log(moment().hour(15).format('HH:mm A'));

    As stated in the documentation, from moment version 1.6.0

    Locale#meridiem should be a callback function that returns the correct string based on hour, minute, and upper/lowercase.

    While on version before 1.6.0:

    Locale#meridiem was a map of upper and lowercase versions of am/pm.

提交回复
热议问题