添加一天到几小时

时间:2014-02-09 19:39:25

标签: php

我有这个:

$time = new DateTime('today 6 PM');
$now = new DateTime('now');
// check if current time is past 6 PM
if ($now > $time) {
     $time = new DateTime('Next Saturday 6 PM');
}

$diff = $time->diff($now);    
echo $diff->format("%h hours %i minutes remaining");

并希望将时间添加到下周六以及每个星期六的时间,所以如果我们达到一个,它应该从头开始自动启动

2 个答案:

答案 0 :(得分:1)

 $plusSix = date('Y-m-d' , strtotime('+6 hours' , time())); // to add 6 hours

检查我想的那天:

$dayNumber = date('w' , strtotime('2012-01-01'));

答案 1 :(得分:0)

您需要分别获取每天,每小时和每分钟:

$diff = $time->diff($now); 
$days = $diff->format("%a");
$hours = $diff->format("%h");
$minutes = $diff->format("%i");
$total_hours = $days * 24 + $hours; //figure out the total hours
echo "$total_hours hours $minutes minutes remaining";
相关问题