$time = Whatever i want
$future_date = new DateTime(date('r',strtotime($time)));
$time_now = time();
$now = new DateTime(date('r', $time_now));
interval = date_diff($future_date, $now);
echo $interval->format('%H:%I');当我运行这个..。我每天都有产出,你就是看不见。我怎样才能把白天变成几个小时(例如,有35个小时)?
这是一个较长的脚本im写作的一部分,我意识到有不同的方式来做这件事.
编辑
利用下面的答案,我得出了如下结论:
$time = '2013-10-8 11:10:00';
$future_date = new DateTime($time);
$now = new DateTime();
$interval = date_diff($future_date, $now);
$text = $interval->days * 24 + $interval->h . ':' . $interval->i; 我正在尝试以这种格式输出小时和分钟(00:00),并使用前导零。现在超出我的深度..。
发布于 2013-10-07 16:20:40
例如,如何以小时为单位获得日期/时间戳之间的差异:
$future = new DateTime('@1383609600');
$now = new DateTime;
$diff = $now->diff($future);
echo $diff->days * 24 + $diff->h;更新:如果希望用前导零格式化输出数字,可以使用sprintf()或str_pad()函数。sprintf()使用示例:
echo sprintf('%02d:%02d', $diff->days * 24 + $diff->h, $diff->i);https://stackoverflow.com/questions/19229690
复制相似问题