时间更复杂的和我想总结只是没有在一天重复多次,看到链接下面的图片,以更好地了解在PHP或学说
http://postimage.org/image/ew50dnlw/
的总时间应该5小时
我不想因为其他时间已经填补了时间
感谢计两次黄色区域!
时间更复杂的和我想总结只是没有在一天重复多次,看到链接下面的图片,以更好地了解在PHP或学说
http://postimage.org/image/ew50dnlw/
的总时间应该5小时
我不想因为其他时间已经填补了时间
感谢计两次黄色区域!
我做了类似的事情,但使用Telerik的RadScheduler,所以我不能提供你的代码,但描述了逻辑。
我假设你已经有一个数组的约会,按开始日期
首先运行命令:
后续运行:
请提供你的代码,这样我就可以帮助您更好地
使用由安德烈提出的想法在上面的回答,我可以用下面的代码实现的目标: 注意:要得到这个工作正常,不要忘记订购您倍起始时间ASC
<?php
// Function to sum times
function sum($time1, $time2) {
$times = array($time1, $time2);
$seconds = 0;
foreach ($times as $time) {
list($hour, $minute, $second) = explode(':', $time);
$seconds += $hour * 3600;
$seconds += $minute * 60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds/60);
$seconds -= $minutes * 60;
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
}
// Function to subtract times
function sub($end, $start) {
$end = strtotime($end);
$start = strtotime($start);
$seconds = $end - $start;
$hours = floor($seconds/3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds/60);
$seconds -= $minutes * 60;
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
}
// Some values to work on
// To get this working the times should be ordered by start time ASC
$start = array(
'11:00:00',
'13:00:00',
'14:00:00',
'15:00:00',
);
$end = array(
'12:30:00',
'14:30:00',
'16:00:00',
'16:30:00',
);
$total = "00:00:00";
$tmp = "00:00:00";
for ($i = 0; $i <= count($start); $i++) {
$start_t = $start[$i];
$end_t = $end[$i];
if ($start_t >= $tmp) {
$total = sum(sub($end_t, $start_t), $total);
$tmp = $end_t;
} else {
if ($end_t > $tmp) {
$total = sum(sub($end_t, $tmp), $total);
$tmp = $end_t;
} else {
}
}
}
echo $total;
,如果你想人来帮助你 – 2011-05-03 13:20:52
你有什么[试图]已经在这里粘贴一段代码? – 2011-05-03 13:21:24