对Moment.js的研究

创建
npm install moment --save-dev

日期格式化

moment().format('MMMM Do YYYY, h:mm:ss a'); // 六月 4日 2019, 6:24:10 晚上
moment().format('dddd');                    // 星期二
moment().format("MMM Do YY");  // 6月 4日 19 moment().format('YYYY [escaped] YYYY');  // 2019 escaped 2019 moment().format();  // 2019-06-04T18:24:10+08:00

相对时间

moment("20111031", "YYYYMMDD").fromNow(); // 8 年前

moment("20120620", "YYYYMMDD").fromNow(); //7 年前

moment().startOf('day').fromNow(); // 18 小时前

moment().endOf('day').fromNow(); // 6 小时内

moment().startOf('hour').fromNow(); // 30 分钟前

日历时间

moment().subtract(10, 'days').calendar(); // 2019年5月25日

moment().subtract(6, 'days').calendar(); // 上周三晚上6点32

moment().subtract(3, 'days').calendar(); // 上周六晚上6点32

moment().subtract(1, 'days').calendar(); // 昨天晚上6点32分

moment().calendar(); // 今天晚上6点32分

moment().add(1, 'days').calendar(); // 明天晚上6点32分

moment().add(3, 'days').calendar(); // 本周五晚上6点32

moment().add(10, 'days').calendar(); // 2019年6月14日

多语言支持

moment().format('L');    // 2019-06-04
moment().format('l');    // 2019-06-04
moment().format('LL');  // 2019年6月4日 moment().format('ll');  // 2019年6月4日 moment().format('LLL');  // 2019年6月4日晚上6点33分 moment().format('lll');  // 2019年6月4日晚上6点33分 moment().format('LLLL'); // 2019年6月4日星期二晚上6点33分 moment().format('llll'); // 2019年6月4日星期二晚上6点33分

































































 















































猜你喜欢

转载自www.cnblogs.com/zhouyideboke/p/10975369.html