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日 20
moment().subtract(3, 'days').calendar(); // 上星期日22:36
moment().subtract(1, 'days').calendar(); // 昨天22:36
moment().calendar(); // 今天22:36
中文文档: http://momentjs.cn/docs/
CDN加速地址:https://cdn.staticfile.org/moment.js/2.9.0/moment.min.js
一个多功能的数字格式化库,支持包括普通数字、货币、百分比,字节、时间等格式化。你也可以自定义格式或符号。支持nodejs
var string = numeral(10000).format('+0,0'); // +10,000
string = numeral(10000).format('0a'); // +10k
string = numeral(1024).format('0b'); // +1KB
string = numeral(0.9876).format('0.0%'); // 98.8%
string = numeral(15).format('00:00:00'); // 0:00:15
string = numeral(63846).format('00:00:00'); // 17:44:06
官方文档 http://numeraljs.com/
CDN加速地址https://cdn.staticfile.org/numeral.js/2.0.6/numeral.min.js