您的位置:首页 > Web前端 > JavaScript

moment.js 对时间变量进行管理

2017-03-13 17:54 323 查看
安装:

bower install moment --save # bower
npm install moment --save   # npm
Install-Package Moment.js   # NuGet
spm install moment --save   # spm
meteor add momentjs:moment  # meteor

相关函数:

moment().format('MMMM Do YYYY, h:mm:ss a'); // March 13th 2017, 5:54:37 pm
moment().format('dddd');                    // Monday
moment().format("MMM Do YY");               // Mar 13th 17
moment().format('YYYY [escaped] YYYY');     // 2017 escaped 2017
moment().format();                          // 2017-03-13T17:54:37+08:00


moment().format('MMMM Do YYYY, h:mm:ss a'); // March 13th 2017, 5:54:37 pm
moment().format('dddd');                    // Monday
moment().format("MMM Do YY");               // Mar 13th 17
moment().format('YYYY [escaped] YYYY');     // 2017 escaped 2017
moment().format();                          // 2017-03-13T17:54:37+08:00


moment().subtract(10, 'days').calendar(); // 03/03/2017
moment().subtract(6, 'days').calendar();  // Last Tuesday at 5:55 PM
moment().subtract(3, 'days').calendar();  // Last Friday at 5:55 PM
moment().subtract(1, 'days').calendar();  // Yesterday at 5:55 PM
moment().calendar();                      // Today at 5:55 PM
moment().add(1, 'days').calendar();       // Tomorrow at 5:55 PM
moment().add(3, 'days').calendar();       // Thursday at 5:55 PM
moment().add(10, 'days').calendar();      // 03/23/201

moment.locale();         // en
moment().format('LT');   // 5:58 PM
moment().format('LTS');  // 5:58:11 PM
moment().format('L');    // 03/13/2017
moment().format('l');    // 3/13/2017
moment().format('LL');   // March 13, 2017
moment().format('ll');   // Mar 13, 2017
moment().format('LLL');  // March 13, 2017 5:58 PM
moment().format('lll');  // Mar 13, 2017 5:58 PM
moment().format('LLLL'); // Monday, March 13, 2017 5:58 PM
moment().format('llll'); // Mon, Mar 13, 2017 5:58 PM
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  moment date