AM/PM1.6.0+

  1. // From 2.12.0 onward
  2. moment.updateLocale('en', {
  3. meridiem : Function
  4. });
  5. // From 2.8.1 to 2.11.2
  6. moment.locale('en', {
  7. meridiem : Function
  8. });
  9. // Deprecated in 2.8.1
  10. moment.lang('en', {
  11. meridiem : Function
  12. });

If your locale uses 'am/pm', Locale#meridiem can be omitted, as those values are the defaults.

If your locale needs any different computation for am/pm, Locale#meridiem should be a callback function that returns the correct string based on hour, minute, and upper/lowercase.

  1. moment.updateLocale('zh-cn', {
  2. meridiem : function (hour, minute, isLowercase) {
  3. if (hour < 9) {
  4. return "早上";
  5. } else if (hour < 11 && minute < 30) {
  6. return "上午";
  7. } else if (hour < 13 && minute < 30) {
  8. return "中午";
  9. } else if (hour < 18) {
  10. return "下午";
  11. } else {
  12. return "晚上";
  13. }
  14. }
  15. });