将日期拆分为多个部分 - PHP/Laravel/Carbon

Split date into parts - PHP/Laravel/Carbon

我开始将 carbon 整合到我的网站中,但似乎无法获得所需的格式。

Carbon::create($year, $month, $day, $hour, $minute, $second, $tz);

// initial data
$day = 'today';
$time = '1100';

// i then convert them
$d = date('Y-m-d',strtotime($day));
$t = date('H:i:s',strtotime($time));

// this is what I end up with
date = "2016-01-05"
time":"11:00:00"

如何将它们与php分开来帮助我提取$year, $month, $day, $hour, $minute, $second

只需使用这样的东西:

$year = date("Y");
$month = date("m");
$day = date("d");
$time = date("H:i:s")
$fulldate =  $year .'-'. $month .'-'. $day

这几乎说明了您是如何完成所有这些工作的。

所以根据评论:

function convertTime($day, $time){
      $d = date('Y-m-d-H-i-s',strtotime($day." +".$time));

      $expD = explode("-", $d);

      $Year = $expD[0];
      $Month = $expD[1];
      $Day   = $expD[2];
      $Hour  = $expD[3];
      $Minute = $expD[4];
      $Second = $expD[5];

      return array($Year, $Month, $Day, $Hour, $Minute, $Second);
}