moment插件的使用姿勢

1. 日期格式化
moment().format('MMMM Do YYYY, h:mm:ss a'); // 三月 7日 2020, 11:59:47 中午
moment().format('dddd'); // 星期六
moment().format("MMM Do YY"); // 3月 7日 20
moment().format('YYYY [escaped] YYYY'); // 2020 escaped 2020
moment().format(); // 2020-03-07T11:59:47+08:00
2. 相對時間
moment("20111031", "YYYYMMDD").fromNow(); // 8 年前
moment("20120620", "YYYYMMDD").fromNow(); // 8 年前
moment().startOf('day').fromNow(); // 12 小時前
moment().endOf('day').fromNow(); // 12 小時內
moment().startOf('hour').fromNow(); // 1 小時前
3. 日歷時間
moment().subtract(10, 'days').calendar(); // 2020/02/26
moment().subtract(6, 'days').calendar(); // 上星期日11:59
moment().subtract(3, 'days').calendar(); // 上星期三11:59
moment().subtract(1, 'days').calendar(); // 昨天11:59
moment().calendar(); // 今天11:59
moment().add(1, 'days').calendar(); // 明天11:59
moment().add(3, 'days').calendar(); // 下星期二11:59
moment().add(10, 'days').calendar(); // 2020/03/17
4. 其他格式
moment.locale(); // zh-cn
moment().format('LT'); // 11:59
moment().format('LTS'); // 11:59:47
moment().format('L'); // 2020/03/07
moment().format('l'); // 2020/3/7
moment().format('LL'); // 2020年3月7日
moment().format('ll'); // 2020年3月7日
moment().format('LLL'); // 2020年3月7日中午11點59分
moment().format('lll'); // 2020年3月7日 11:59
moment().format('LLLL'); // 2020年3月7日星期六中午11點59分
moment().format('llll'); // 2020年3月7日星期六 11:59
5. 常用格式
moment().format("YYYY年MM月DD日 HH時mm分ss秒"); //2020年04月20日 18時59分50秒
moment(1711641720000).format('YYYY-MM-DD HH:mm:ss'); //2020-04-20 18:59:50(24小時制)
moment(1711641720000).format('YYYY-MM-DD hh:mm:ss'); //2020-04-20 06:59:50(12小時制)
moment 文檔