格式化Moment.js am / pm以包含句点/点 [英] Format Moment.js am/pm to include periods/dots

查看:1301
本文介绍了格式化Moment.js am / pm以包含句点/点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遇到一个小的格式化问题与时刻的 a 输入。

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

a / A将返回上午/上午PM /下午,但是有没有办法格式化以包括期间?

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

IE a.m。 pm 这是对客户端重要的格式更改,我无法使用时间文档找到修复程序。

I.E. a.m. p.m. it's a format change that is important to the client and I haven't been able to find the fix with moment's documentation

我尝试过



I've tried

moment.updateLocale('en', {
    meridiem : {
        am : 'a.m.',
        AM : 'A.M.',
        pm : 'p.m.',
        PM : 'P.M.'
    }
}); 

没有成功

是否可能?

推荐答案

您用于自定义meridiem的方法适用于版本< 1.6.0。您应该在较新版本中提供更新meridiem的功能。请参阅文档了解更多信息:

The method you used to customize the meridiem applies to versions < 1.6.0. You should provide a function in newer versions to update meridiem. Please see the docs for more info:

moment.updateLocale('en', {
  meridiem: function(hour, minute, isLowerCase) {
    if (hour < 12) {
      return 'a.m.';
    } else {
      return 'p.m.';
    }
  }
});

这篇关于格式化Moment.js am / pm以包含句点/点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆