時間更復雜的和我想總結只是沒有在一天重複多次,看到鏈接下面的圖片,以更好地瞭解在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