【问题标题】:php the most correct way to convert i:s minutes and seconds to secondsphp将i:s分秒转秒的最正确方法
【发布时间】:2013-01-13 09:08:28
【问题描述】:

date('i:s',600) 将显示十分钟:10:00。美好而完美。我不在乎时间。

我需要从字符串'10:00' 中获取 600 的反向函数吗?

所以,我正在寻找 date('i:s',$secs) 的反向函数

$secs 可以是从“00:00”到“59:59”的任何正确分钟和秒时间。

【问题讨论】:

    标签: php function date time seconds


    【解决方案1】:
    function reverse($secs) {
      list($i, $s) = explode(':', $secs);
      return $i*60 + $s;
    }
    

    再多的就太过分了。

    【讨论】:

      【解决方案2】:

      不确定strtotime 的效率如何,但您可以这样做:

      function seconds($time)
      {
          return (strtotime("00:" . $time) - strtotime("00:00:00"));
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-02
        • 2016-05-03
        • 1970-01-01
        • 2015-03-01
        • 2011-03-11
        • 1970-01-01
        相关资源
        最近更新 更多