<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Moment.js日期處理庫的使用

          共 2119字,需瀏覽 5分鐘

           ·

          2021-12-17 10:03

          Moment.js


          Moment.js是一個(gè)輕量級(jí)的JavaScript時(shí)間庫,它方便了日常開發(fā)中對(duì)時(shí)間的操作,提高了開發(fā)效率。這個(gè)在一些金融保險(xiǎn)公司會(huì)經(jīng)常用到,比如一下時(shí)間的格式化處理,時(shí)間的選擇等等。
          這個(gè)比較好的地方是可以格式化時(shí)間(很常用),日歷的選擇、多語言支持等等。


          幾種安裝方式(選擇其中一種即可)


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


          官方文檔


          http://momentjs.cn/



          moment.js下載

          http://cdn.staticfile.org/moment.js/2.24.0/moment.js


          moment.js多語言下載

          http://cdn.staticfile.org/moment.js/2.24.0/moment-with-locales.js



          引入



          var moment = require('moment');moment().format();


          日期格式化

          moment().format('MMMM Do YYYY, h:mm:ss a'); // 十二月 16日 2021, 4:22:44 下午moment().format('dddd');                    // 星期四moment().format("MMM Do YY");               // 12月 16日 21moment().format('YYYY [escaped] YYYY');     // 2021 escaped 2021moment().format();                          // 2021-12-16T16:22:44+08:00

          相對(duì)時(shí)間

          moment("20111031", "YYYYMMDD").fromNow(); // 10 年前moment("20120620", "YYYYMMDD").fromNow(); // 9 年前moment().startOf('day').fromNow();        // 16 小時(shí)前moment().endOf('day').fromNow();          // 8 小時(shí)內(nèi)moment().startOf('hour').fromNow();       // 23 分鐘前


          日歷時(shí)間

          moment().subtract(10, 'days').calendar(); // 2021/12/06moment().subtract(6, 'days').calendar();  // 上星期五16:22moment().subtract(3, 'days').calendar();  // 上星期一16:22moment().subtract(1, 'days').calendar();  // 昨天16:22moment().calendar();                      // 今天16:22moment().add(1, 'days').calendar();       // 明天16:22moment().add(3, 'days').calendar();       // 下星期日16:22moment().add(10, 'days').calendar();      // 2021/12/26

          多語言支持

          moment.locale();         // zh-cnmoment().format('LT');   // 16:22moment().format('LTS');  // 16:22:44moment().format('L');    // 2021/12/16moment().format('l');    // 2021/12/16moment().format('LL');   // 2021年12月16日moment().format('ll');   // 2021年12月16日moment().format('LLL');  // 2021年12月16日下午4點(diǎn)22分moment().format('lll');  // 2021年12月16日 16:22moment().format('LLLL'); // 2021年12月16日星期四下午4點(diǎn)22分moment().format('llll'); // 2021年12月16日星期四 16:22



          好啦,本期內(nèi)容就分享到這里,我們下期見!



          瀏覽 37
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲三级片免费观看 | 操逼18禁 | 国产福利激情视频 | 最新黄色成人网站 | av婷婷免费 |