PHP:保持时间相对于开始日期的提前


PHP: Keeping times relative forward of a start date

堆栈溢出,

我需要一些指导:

假设我有一个时间列表(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