久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <i id='tzP3z'><tr id='tzP3z'><dt id='tzP3z'><q id='tzP3z'><span id='tzP3z'><b id='tzP3z'><form id='tzP3z'><ins id='tzP3z'></ins><ul id='tzP3z'></ul><sub id='tzP3z'></sub></form><legend id='tzP3z'></legend><bdo id='tzP3z'><pre id='tzP3z'><center id='tzP3z'></center></pre></bdo></b><th id='tzP3z'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tzP3z'><tfoot id='tzP3z'></tfoot><dl id='tzP3z'><fieldset id='tzP3z'></fieldset></dl></div>
    1. <tfoot id='tzP3z'></tfoot>
      • <bdo id='tzP3z'></bdo><ul id='tzP3z'></ul>

        <small id='tzP3z'></small><noframes id='tzP3z'>

        <legend id='tzP3z'><style id='tzP3z'><dir id='tzP3z'><q id='tzP3z'></q></dir></style></legend>
      1. 用于人類友好的相對日期格式的 Javascript 庫

        Javascript library for human-friendly relative date formatting(用于人類友好的相對日期格式的 Javascript 庫)
          <i id='C0UIl'><tr id='C0UIl'><dt id='C0UIl'><q id='C0UIl'><span id='C0UIl'><b id='C0UIl'><form id='C0UIl'><ins id='C0UIl'></ins><ul id='C0UIl'></ul><sub id='C0UIl'></sub></form><legend id='C0UIl'></legend><bdo id='C0UIl'><pre id='C0UIl'><center id='C0UIl'></center></pre></bdo></b><th id='C0UIl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='C0UIl'><tfoot id='C0UIl'></tfoot><dl id='C0UIl'><fieldset id='C0UIl'></fieldset></dl></div>
            <tbody id='C0UIl'></tbody>

              <legend id='C0UIl'><style id='C0UIl'><dir id='C0UIl'><q id='C0UIl'></q></dir></style></legend>

                <bdo id='C0UIl'></bdo><ul id='C0UIl'></ul>
                • <small id='C0UIl'></small><noframes id='C0UIl'>

                  <tfoot id='C0UIl'></tfoot>
                • 本文介紹了用于人類友好的相對日期格式的 Javascript 庫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想以人性化的格式顯示一些相對于當前日期的日期.

                  I'd like to display some dates as relative to the current date in a human-friendly format.

                  人類友好的相對日期示例:

                  Examples of human-friendly relative dates:

                  • 10 秒前
                  • 20 分鐘后
                  • 1 天前
                  • 5 周前
                  • 2 個月前

                  基本上忠實地保留最高數量級(并且優先考慮,僅在超過其中 2 個單位時上調單位 - 5 周而不是 1 個月).

                  Basically faithfully preserving the highest order of magnitude (and by preference, only shifting up units when passing 2 of those units - 5 weeks instead of 1 month).

                  雖然我可以接受一個控制較少且日期更友好的圖書館,例如:

                  Though I could live with a library that had less control and even more friendly dates like:

                  • 昨天
                  • 明天
                  • 上周
                  • 幾分鐘前
                  • 幾個小時后

                  有任何流行的圖書館嗎?

                  Any popular libraries for this?

                  推薦答案

                  自從我寫了這個答案,一個眾所周知的可用庫是 moment.js.

                  Since I wrote this answer, a well known library available is moment.js.

                  有可用的庫,但自己實現它很簡單.只需使用少數幾個條件.

                  There are libraries available, but it is trivial to implement it yourself. Just use a handful of conditions.

                  假設 date 是一個實例化的 Date 對象,用于您要與之進行比較的時間.

                  Assume date is an instantiated Date object for the time you want to make a comparison against.

                  // Make a fuzzy time
                  var delta = Math.round((+new Date - date) / 1000);
                  
                  var minute = 60,
                      hour = minute * 60,
                      day = hour * 24,
                      week = day * 7;
                  
                  var fuzzy;
                  
                  if (delta < 30) {
                      fuzzy = 'just then.';
                  } else if (delta < minute) {
                      fuzzy = delta + ' seconds ago.';
                  } else if (delta < 2 * minute) {
                      fuzzy = 'a minute ago.'
                  } else if (delta < hour) {
                      fuzzy = Math.floor(delta / minute) + ' minutes ago.';
                  } else if (Math.floor(delta / hour) == 1) {
                      fuzzy = '1 hour ago.'
                  } else if (delta < day) {
                      fuzzy = Math.floor(delta / hour) + ' hours ago.';
                  } else if (delta < day * 2) {
                      fuzzy = 'yesterday';
                  }
                  

                  您需要調整它以處理未來的日期.

                  You would need to adapt this to handle future dates.

                  這篇關于用于人類友好的相對日期格式的 Javascript 庫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)

                  <small id='0Vh02'></small><noframes id='0Vh02'>

                    <bdo id='0Vh02'></bdo><ul id='0Vh02'></ul>
                        <tfoot id='0Vh02'></tfoot>

                          <legend id='0Vh02'><style id='0Vh02'><dir id='0Vh02'><q id='0Vh02'></q></dir></style></legend>
                            <tbody id='0Vh02'></tbody>
                          1. <i id='0Vh02'><tr id='0Vh02'><dt id='0Vh02'><q id='0Vh02'><span id='0Vh02'><b id='0Vh02'><form id='0Vh02'><ins id='0Vh02'></ins><ul id='0Vh02'></ul><sub id='0Vh02'></sub></form><legend id='0Vh02'></legend><bdo id='0Vh02'><pre id='0Vh02'><center id='0Vh02'></center></pre></bdo></b><th id='0Vh02'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0Vh02'><tfoot id='0Vh02'></tfoot><dl id='0Vh02'><fieldset id='0Vh02'></fieldset></dl></div>

                            主站蜘蛛池模板: 色综合久| 一区二区三区四区电影 | 青青草亚洲 | 精品国产99 | 成年人国产在线观看 | 欧美激情国产日韩精品一区18 | 九九热在线视频 | 成人午夜视频在线观看 | 亚洲精品3 | 中文字幕av免费 | 337p日韩| 成人欧美一区二区三区 | 成人在线视频一区 | 在线亚洲免费视频 | 欧美日韩国产在线观看 | 亚洲高清视频在线观看 | 久久精品成人热国产成 | 久久99精品久久久 | 中文字幕第100页 | 久久网一区二区三区 | 美女天天干 | a级片网站| 国产成人精品免费视频大全最热 | 欧美 日韩 国产 一区 | 在线播放国产一区二区三区 | 视频一区在线 | 国产精品99久久久精品免费观看 | 亚洲综合成人网 | 国产精品久久久久久网站 | 亚洲成人在线视频播放 | 久久伊人精品 | 天堂色网| 美女毛片免费看 | 中文字幕在线一区二区三区 | 亚洲一区 中文字幕 | 综合成人在线 | 欧美极品一区二区 | 99精品免费久久久久久久久日本 | 亚洲第一福利视频 | 欧美日韩在线一区二区三区 | 日韩第一页 |