堆栈溢出,
我需要一些指导:
说我有一个时间列表(03.30, 04.35, 05.30, 08.05...23.00, 23.50, 00.36).
现在我知道开始日期,因此对于00:00到23:59之间的时间,我可以简单地使用strtotime($ time,$ date)获得给定时间的有效时间戳。但是,我很难获得防弹时间戳的时间是午夜之后的时间-使用strtotime($ time,$ date)会给我今天的时间戳,而不是下一个日期。
希望这会有意义,并且有人可以指出我正确的方向。
我已经完成了强制性搜索,但是我认为我的要求表达不正确:(
如果我正确地认为列表始终排序并且今天最早的时间比明天的时间高,那么:
$list = array(03.30, 04.35, 05.30, 08.05, 23.00, 23.50, 00.36);
$nextday = $list[0];
$today = date("Y-m-d", time());
foreach ($list as $item) {
// need to convert to time format h:i
$time = str_replace('.',':', $item);
if ($item < $nextday) echo date("Y-m-d H:i:s", strtotime($today.' '.$time.' +1 day '))."\n";
else echo date("Y-m-d H:i:s", strtotime($today.' '.$time))."\n";
}
结果
2015-06-01 03:03:00
2015-06-01 04:35:00
...
2015-06-01 23:05:00
2015-06-02 00:36:00
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句