Php 如何在Laravel中创建碳日期
如果日期部分采用以下格式“d M Y”,并且小时和分钟作为整数存在于单独的变量中,那么如何创建碳日期 例如 目前,我不得不这样做,但它也最终增加了当前秒数Php 如何在Laravel中创建碳日期,php,laravel-5,php-carbon,Php,Laravel 5,Php Carbon,如果日期部分采用以下格式“d M Y”,并且小时和分钟作为整数存在于单独的变量中,那么如何创建碳日期 例如 目前,我不得不这样做,但它也最终增加了当前秒数 Carbon::createFromFormat('d M Y', $this->start_dt)->hour($this->start_hr)->minute($this->start_min); 结果2016-02-06 12:00:44 有没有一种更干净的方法来创建碳日期,而无需将时间和分钟连成一条链,
Carbon::createFromFormat('d M Y', $this->start_dt)->hour($this->start_hr)->minute($this->start_min);
结果2016-02-06 12:00:44
有没有一种更干净的方法来创建碳日期,而无需将时间和分钟连成一条链,并将秒数设置为00
可能是这样,但它不起作用:
Carbon::createFromFormat('d M Y H:i', $this->start_dt, $this->start_hr, $this->start_min);
*更新*
设法弄明白:
Carbon::createFromFormat('d M Y H:i:s', $this->start_dt . ' ' . $this->start_hr . ':'. $this->start_min . ':00');
如果您愿意使用createFromFormat,则必须将第二个参数作为如下字符串输入:
$dt=Carbon\Carbon::createFromFormat('d M Y H:i', $this->start_dt.' '.$this->start_hr.':'.$this->start_min);
如果您愿意使用createFromFormat,则必须将第二个参数作为如下字符串输入:
$dt=Carbon\Carbon::createFromFormat('d M Y H:i', $this->start_dt.' '.$this->start_hr.':'.$this->start_min);
解决方案:
Carbon::createFromFormat('d M Y', $this->start_dt)
->setTime($this->start_hr, $this->start_min);
解决方案:
Carbon::createFromFormat('d M Y', $this->start_dt)
->setTime($this->start_hr, $this->start_min);
你不能随意添加秒数吗?嘿,就像你的编辑一样。你不能随意添加秒数吗?嘿,就像你的编辑一样
Carbon::createFromFormat('d M Y', $this->start_dt)
->setTime($this->start_hr, $this->start_min);