Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Laravel中创建碳日期_Php_Laravel 5_Php Carbon - Fatal编程技术网

Php 如何在Laravel中创建碳日期

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 有没有一种更干净的方法来创建碳日期,而无需将时间和分钟连成一条链,

如果日期部分采用以下格式“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

有没有一种更干净的方法来创建碳日期,而无需将时间和分钟连成一条链,并将秒数设置为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);