moment.js

Format Dates

moment().format('MMMM Do YYYY, h:mm:ss a'); // 八月 4日 2015, 7:50:39 晚上
moment().format('dddd');  // 星期二
moment().format("MMM Do YY");  // 8月 4日 15
moment().format('YYYY [escaped] YYYY');  // 2015 escaped 2015
moment().format();  // 2015-08-04T19:50:39+08:00

Relative Time

moment("20111031", "YYYYMMDD").fromNow(); // 4 年前moment("20120620", "YYYYMMDD").fromNow(); // 3 年前moment().startOf('day').fromNow();  // 20 小时前moment().endOf('day').fromNow();  // 4 小时内moment().startOf('hour').fromNow();  // 1 小时前

Calendar Time

moment().subtract(10, 'days').calendar(); // 2015年7月25日moment().subtract(6, 'days').calendar();  // 上周三晚上7点50moment().subtract(3, 'days').calendar();  // 上周六晚上7点50moment().subtract(1, 'days').calendar();  // 昨天晚上7点50分moment().calendar();  // 今天晚上7点50分
moment().add(1, 'days').calendar();  // 明天晚上7点50分
moment().add(3, 'days').calendar();  // 本周五晚上7点50
moment().add(10, 'days').calendar();  // 2015年8月14日

Multiple Locale Support

moment().format('L');  // 2015-08-04
moment().format('l');  // 2015-08-04
moment().format('LL');  // 2015年8月4日
moment().format('ll');  // 2015年8月4日
moment().format('LLL');  // 2015年8月4日晚上7点50分
moment().format('lll');  // 2015年8月4日晚上7点50分moment().format('LLLL'); // 2015年8月4日星期二晚上7点50分moment().format('llll');

你可能感兴趣的:(moment.js)