<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如何查找自日期时间以来经过的时间?

        PHP How to find the time elapsed since a date time?(PHP如何查找自日期时间以来经过的时间?)
          <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如何查找自日期时间以来经过的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

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

                      <tbody id='CUio9'></tbody>
                  • <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>