Moment-JavaScript 日期处理类库

来源:http://momentjs.cn/

日期格式化

moment().format('MMMM Do YYYY, h:mm:ss a'); // 二月 22日 2017, 4:04:26 下午
moment().format('dddd');                    // 星期三
moment().format("MMM Do YY");               // 2月 22日 17
moment().format('YYYY [escaped] YYYY');     // 2017 escaped 2017
moment().format();                          // 2017-02-22T16:04:26+08:00

相对时间

moment("20111031", "YYYYMMDD").fromNow(); // 5 年前
moment("20120620", "YYYYMMDD").fromNow(); // 5 年前
moment().startOf('day').fromNow();        // 16 小时前
moment().endOf('day').fromNow();          // 8 小时内
moment().startOf('hour').fromNow();       // 4 分钟前

日历时间

moment().subtract(10, 'days').calendar(); // 2017年2月12日
moment().subtract(6, 'days').calendar();  // 上周四下午4点04
moment().subtract(3, 'days').calendar();  // 上周日下午4点04
moment().subtract(1, 'days').calendar();  // 昨天下午4点04分
moment().calendar();                      // 今天下午4点04分
moment().add(1, 'days').calendar();       // 明天下午4点04分
moment().add(3, 'days').calendar();       // 本周六下午4点04
moment().add(10, 'days').calendar();      // 2017年3月4日

多语言支持

moment().format('L');    // 2017-02-22
moment().format('l');    // 2017-02-22
moment().format('LL');   // 2017年2月22日
moment().format('ll');   // 2017年2月22日
moment().format('LLL');  // 2017年2月22日下午4点04分
moment().format('lll');  // 2017年2月22日下午4点04分
moment().format('LLLL'); // 2017年2月22日星期三下午4点04分
moment().format('llll');
原文地址:https://www.cnblogs.com/youfeng365/p/6429417.html