MomentJS - 相对时间



此方法有助于获取相对时间。

语法

moment.updateLocale('en', {
   relativeTime : Object
});

示例

var localeData = moment.updateLocale('en', {
   relativeTime: {
      future: "in %s",
      past: "%s ago",
      s: 'hello, a few seconds',
      ss: '%d seconds',
      m: "a minute",
      mm: "%d minutes",
      h: "an hour",
      hh: "%d hours",
      d: "a day",
      dd: "%d days",
      M: "a month",
      MM: "%d months",
      y: "a year",
      yy: "%d years"
   }
});
var m = moment().fromNow();

输出

Relative
momentjs_customization.htm
广告