moment.js中文api

当前日期格式化

moment().format('MMMM Do YYYY, h:mm:ss a'); -> 六月 18日 2015, 2:06:40 下午

moment().format('dddd'); -> 星期四

moment().format("MMM Do YY"); -> 6月 18日 15

moment().format('YYYY [escaped] YYYY'); -> 2015 escaped 2015

moment().format(); -> 2015-06-18T14:06:40+08:00

---------------------------------------------------
moment().format('YYYY-MM-DD'); -> 2015-06-18

moment().format('YYYY-MM-DD h:mm:ss a'); -> 2015-06-18 02:06:40 下午

指定日期格式化
moment("20111031", "YYYYMMDD").fromNow(); -> 4年前

moment("20120620", "YYYYMMDD").fromNow(); -> 3年前

moment().startOf('day').fromNow(); -> 14小时前

moment().endOf('day').fromNow(); -> 10小时内

moment().startOf('hour').fromNow(); -> 7分钟前

当前日期向前或者向后推的日期格式化
moment().subtract(10, 'days').calendar(); -> 2015年6月8日

moment().subtract(6, 'days').calendar(); -> 上周五下午2点06

moment().subtract(3, 'days').calendar(); -> 本周一下午2点06

moment().subtract(1, 'days').calendar(); -> 昨天下午2点06

moment().calendar(); -> 今天下午2点06

moment().add(1, 'days').calendar(); -> 明天下午2点06

moment().add(3, 'days').calendar(); -> 本周日下午2点06

moment().add(10, 'days').calendar(); -> 2015年6月28日

也可以使用下面方式日期格式化
moment().format('L'); -> 2015-06-18

moment().format('l'); -> 2015-06-18

moment().format('LL'); -> 2015年6月18日

moment().format('ll'); -> 2015年6月18日

moment().format('LLL'); -> 2015年6月18日下午2点06

moment().format('lll'); -> 2015年6月18日下午2点06

moment().format('LLLL'); -> 2015年6月18日星期四下午2点06

moment().format('llll'); -> 2015年6月18日星期四下午2点06

http://momentjs.com/

原文地址:https://www.cnblogs.com/foreveryu/p/4585738.html