多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## JavaScript 日期处理类库 [http://momentjs.cn/](http://momentjs.cn/) ### 日期格式化 ~~~js moment().format('MMMM Do YYYY, h:mm:ss a'); // 十月 19日 2019, 10:15:07 上午 moment().format('dddd'); // 星期六 moment().format("MMM Do YY"); // 10月 19日 19 moment().format('YYYY [escaped] YYYY'); // 2019 escaped 2019 moment().format(); // 2019-10-19T10:15:07+08:00 ~~~ ### 相对时间 ~~~js moment("20111031", "YYYYMMDD").fromNow(); // 8 年前 moment("20120620", "YYYYMMDD").fromNow(); // 7 年前 moment().startOf('day').fromNow(); // 10 小时前 moment().endOf('day').fromNow(); // 14 小时内 moment().startOf('hour').fromNow(); // 15 分钟前 ~~~ ### 日历时间 ~~~js moment().subtract(10, 'days').calendar(); // 2019年10月9日 moment().subtract(6, 'days').calendar(); // 上周日上午10点15 moment().subtract(3, 'days').calendar(); // 本周三上午10点15 moment().subtract(1, 'days').calendar(); // 昨天上午10点15分 moment().calendar(); // 今天上午10点15分 moment().add(1, 'days').calendar(); // 明天上午10点15分 moment().add(3, 'days').calendar(); // 下周二上午10点15 moment().add(10, 'days').calendar(); // 2019年10月29日 ~~~ ### 多语言支持 ~~~js moment().format('L'); // 2019-10-19 moment().format('l'); // 2019-10-19 moment().format('LL'); // 2019年10月19日 moment().format('ll'); // 2019年10月19日 moment().format('LLL'); // 2019年10月19日上午10点15分 moment().format('lll'); // 2019年10月19日上午10点15分 moment().format('LLLL'); // 2019年10月19日星期六上午10点15分 moment().format('llll'); // 2019年10月19日星期六上午10点15分 ~~~