JS本身的Date对象用起来很是繁琐,moment库提供了日期格式化、相对时间、日历时间、时间戳转换等方法。使用起来及其方便,支持nodejs
//部分代码实例moment().format('MMMM Do YYYY, h:mm:ss a'); // 九月 9日 2020, 10:36:27 晚上moment().format('dddd'); // 星期三moment().format("MMM Do YY"); // 9月 9日 20moment().subtract(3, 'days').calendar(); // 上星期日22:36moment().subtract(1, 'days').calendar(); // 昨天22:36moment().calendar(); // 今天22:36
中文文档: http://momentjs.cn/docs/
CDN加速地址:https://cdn.staticfile.org/moment.js/2.9.0/moment.min.js