【问题标题】:Time difference in minutes & seconds? [closed]分秒的时差? [关闭]
【发布时间】:2013-12-13 09:07:07
【问题描述】:

以分钟和秒为单位的时差

问题:需要转换的差异只有分钟和秒

    expected output : 130:04 (i:s)

    example : 

    $fromdate = "12/12/2013 21:00:02"

    $endData = "12/12/2013 23:10:06"

tried : date('i:s', strtotime( $endData) - strtotime( $fromdate));

【问题讨论】:

  • 到目前为止,您尝试了什么,请发布您的代码,以便我们查看您哪里出错了。如果您只是希望我们为您完成工作,那么您来错地方了

标签: php datetime logic


【解决方案1】:

答案如下:

$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
$totalMinutes = round(abs($to_time - $from_time) / 60,2);
$hours = intval($totalMinutes/60);
$minutes = $totalMinutes - ($hours * 60);

已编辑。

或者正如蒂娜·斯莫阿斯在their answer 中建议的那样:

试试:

功能:

function date_difference ($date1timestamp, $date2timestamp) {
$all = round(($date1timestamp - $date2timestamp) / 60);
$d = floor ($all / 1440);
$h = floor (($all - $d * 1440) / 60);
$m = $all - ($d * 1440) - ($h * 60);
//Since you need just hours and mins
return array('hours'=>$h, 'mins'=>$m);
}

调用函数:

$result = date_difference($date1timestamp, $date2timestamp);

【讨论】:

  • 谢谢,但它只显示分钟需要分钟秒也塞尔吉奥
  • 现在您可以按照自己的要求获得分钟和小时。
  • no sergio ,130:04 (m:s)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-29
  • 2016-07-18
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多