<bdo id='4kQ6r'></bdo><ul id='4kQ6r'></ul>

        <small id='4kQ6r'></small><noframes id='4kQ6r'>

        <i id='4kQ6r'><tr id='4kQ6r'><dt id='4kQ6r'><q id='4kQ6r'><span id='4kQ6r'><b id='4kQ6r'><form id='4kQ6r'><ins id='4kQ6r'></ins><ul id='4kQ6r'></ul><sub id='4kQ6r'></sub></form><legend id='4kQ6r'></legend><bdo id='4kQ6r'><pre id='4kQ6r'><center id='4kQ6r'></center></pre></bdo></b><th id='4kQ6r'></th></span></q></dt></tr></i><div id='4kQ6r'><tfoot id='4kQ6r'></tfoot><dl id='4kQ6r'><fieldset id='4kQ6r'></fieldset></dl></div>
        <legend id='4kQ6r'><style id='4kQ6r'><dir id='4kQ6r'><q id='4kQ6r'></q></dir></style></legend>
        <tfoot id='4kQ6r'></tfoot>

        PHP如何查找自日期时间以来经过的时间?

        时间:2024-04-13
          <tfoot id='qa9oY'></tfoot>

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

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

              • <bdo id='qa9oY'></bdo><ul id='qa9oY'></ul>

                    <tbody id='qa9oY'></tbody>
                • <i id='qa9oY'><tr id='qa9oY'><dt id='qa9oY'><q id='qa9oY'><span id='qa9oY'><b id='qa9oY'><form id='qa9oY'><ins id='qa9oY'></ins><ul id='qa9oY'></ul><sub id='qa9oY'></sub></form><legend id='qa9oY'></legend><bdo id='qa9oY'><pre id='qa9oY'><center id='qa9oY'></center></pre></bdo></b><th id='qa9oY'></th></span></q></dt></tr></i><div id='qa9oY'><tfoot id='qa9oY'></tfoot><dl id='qa9oY'><fieldset id='qa9oY'></fieldset></dl></div>
                • 本文介绍了PHP如何查找自日期时间以来经过的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何查找自像 2010-04-28 17:25:43 这样的日期时间戳以来经过的时间,最终输出的文本应该像 xx Minutes Ago/xx 天前

                  How to find the time elapsed since a date time stamp like 2010-04-28 17:25:43, final out put text should be like xx Minutes Ago/xx Days Ago

                  推荐答案

                  大多数答案似乎都集中在将日期从字符串转换为时间.您似乎主要考虑将日期转换为5 天前"格式等.对吗?

                  Most of the answers seem focused around converting the date from a string to time. It seems you're mostly thinking about getting the date into the '5 days ago' format, etc.. right?

                  这就是我要这样做的方式:

                  This is how I'd go about doing that:

                  $time = strtotime('2010-04-28 17:25:43');
                  
                  echo 'event happened '.humanTiming($time).' ago';
                  
                  function humanTiming ($time)
                  {
                  
                      $time = time() - $time; // to get the time since that moment
                      $time = ($time<1)? 1 : $time;
                      $tokens = array (
                          31536000 => 'year',
                          2592000 => 'month',
                          604800 => 'week',
                          86400 => 'day',
                          3600 => 'hour',
                          60 => 'minute',
                          1 => 'second'
                      );
                  
                      foreach ($tokens as $unit => $text) {
                          if ($time < $unit) continue;
                          $numberOfUnits = floor($time / $unit);
                          return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
                      }
                  
                  }
                  

                  我还没有测试过,但它应该可以工作.

                  I haven't tested that, but it should work.

                  结果会是这样的

                  event happened 4 days ago
                  

                  event happened 1 minute ago
                  

                  干杯

                  这篇关于PHP如何查找自日期时间以来经过的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中将时间戳转换为时间前,例如 1 天前、2 天前...... 下一篇:PHP:从时间戳产生相对日期/时间

                  相关文章

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

                • <tfoot id='CUio9'></tfoot>

                • <legend id='CUio9'><style id='CUio9'><dir id='CUio9'><q id='CUio9'></q></dir></style></legend>
                  <i id='CUio9'><tr id='CUio9'><dt id='CUio9'><q id='CUio9'><span id='CUio9'><b id='CUio9'><form id='CUio9'><ins id='CUio9'></ins><ul id='CUio9'></ul><sub id='CUio9'></sub></form><legend id='CUio9'></legend><bdo id='CUio9'><pre id='CUio9'><center id='CUio9'></center></pre></bdo></b><th id='CUio9'></th></span></q></dt></tr></i><div id='CUio9'><tfoot id='CUio9'></tfoot><dl id='CUio9'><fieldset id='CUio9'></fieldset></dl></div>

                        <bdo id='CUio9'></bdo><ul id='CUio9'></ul>