将日期拆分为多个部分-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

因此基于注释:

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);
}

只需使用以下内容:

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

这几乎说明了你是如何做到这一切的。