以下的DEMO直接摘自官网的首页。
Formatting dates
moment().format('MMMM Do YYYY, h:mm:ss a'); moment().format('dddd'); moment().format("MMM Do YY"); moment().format('YYYY [escaped] YYYY'); moment().format();
输出
April 17th 2013, 4:06:00 pm
Wednesday
Apr 17th 13
2013 escaped 2013
2013-04-17T16:06:00+08:00
Timeago
moment("20111031", "YYYYMMDD").fromNow(); moment("20120620", "YYYYMMDD").fromNow(); moment().startOf('day').fromNow(); moment().endOf('day').fromNow(); moment().startOf('hour').fromNow();
输出
a year ago
10 months ago
16 hours ago
in 8 hours
6 minutes ago
Calendar Time
moment().subtract('days', 10).calendar(); moment().subtract('days', 6).calendar(); moment().subtract('days', 3).calendar(); moment().subtract('days', 1).calendar(); moment().calendar(); moment().add('days', 1).calendar(); moment().add('days', 3).calendar(); moment().add('days', 10).calendar();
04/07/2013
last Thursday at 4:06 PM
last Sunday at 4:06 PM
Yesterday at 4:06 PM
Today at 4:06 PM
Tomorrow at 4:06 PM
Saturday at 4:06 PM
04/27/2013
Internationalization
moment().format('L'); moment().format('LL'); moment().format('LLL'); moment().format('LLLL');
04/17/2013
April 17 2013
April 17 2013 4:06 PM
还有多种语言可以选择(包括简体中文和繁体中文哦),详情请见: http://momentjs.com/