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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM