<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>moment.js(日期处理类库)的使用</title> <script src="moment.js"></script> <script src="moment-with-locales.js"></script> </head> <body> <script> /* moment.js version : 2.18.1 Format Dates moment().format('MMMM Do YYYY, h:mm:ss a'); // September 6th 2017, 4:17:22 pm moment().format('dddd'); // Wednesday moment().format("MMM Do YY"); // Sep 6th 17 moment().format('YYYY [escaped] YYYY'); // 2017 escaped 2017 moment().format(); // 2017-09-06T16:17:22+08:00 Relative Time moment("20111031", "YYYYMMDD").fromNow(); // 6 years ago moment("20120620", "YYYYMMDD").fromNow(); // 5 years ago moment().startOf('day').fromNow(); // 16 hours ago moment().endOf('day').fromNow(); // in 8 hours moment().startOf('hour').fromNow(); // 17 minutes ago Calendar Time moment().subtract(10, 'days').calendar(); // 08/27/2017 moment().subtract(6, 'days').calendar(); // Last Thursday at 4:17 PM moment().subtract(3, 'days').calendar(); // Last Sunday at 4:17 PM moment().subtract(1, 'days').calendar(); // Yesterday at 4:17 PM moment().calendar(); // Today at 4:17 PM moment().add(1, 'days').calendar(); // Tomorrow at 4:17 PM moment().add(3, 'days').calendar(); // Saturday at 4:17 PM moment().add(10, 'days').calendar(); // 09/16/2017 Multiple Locale Support moment.locale(); // en moment().format('LT'); // 4:17 PM moment().format('LTS'); // 4:17:22 PM moment().format('L'); // 09/06/2017 moment().format('l'); // 9/6/2017 moment().format('LL'); // September 6, 2017 moment().format('ll'); // Sep 6, 2017 moment().format('LLL'); // September 6, 2017 4:17 PM moment().format('lll'); // Sep 6, 2017 4:17 PM moment().format('LLLL'); // Wednesday, September 6, 2017 4:17 PM moment().format('llll');*/ console.log(moment.locale('zh-cn')); console.log(moment().format('L')); console.log(moment().format('YYYY-MM-DD')); console.log(moment("/Date(1198908717056)/")); console.log(moment("/Date(1198908717056)/")._d); console.log(moment(moment("/Date(1198908717056)/")._d).format('YYYY-MM-DD')); </script> </body> </html>
来源:https://www.cnblogs.com/qixianchuan/p/11162799.html