如何在Laravel中创建一个Carbon日期

How do you I create a Carbon date if I have the date part in the following format 'd M Y' and I have hours and minutes in separate variables as integers.

eg.

$this->start_dt  = '06 Feb 2016'
$this->start_hr  = '12'
$this->start_min  = '00'

Currently I'm having to do this but it also ends up adding the current seconds.

Carbon::createFromFormat('d M Y', $this->start_dt)->hour($this->start_hr)->minute($this->start_min);

result 2016-02-06 12:00:44

Is there a more cleaner way to create a carbon date without having to chain the hours and minutes and to set the seconds to 00?

Maybe something like this but it doesn't work:

Carbon::createFromFormat('d M Y H:i', $this->start_dt, $this->start_hr, $this->start_min);

* UPDATE *

Manage to figure out:

 Carbon::createFromFormat('d M Y H:i:s', $this->start_dt . ' ' . $this->start_hr . ':'. $this->start_min . ':00');
查看全部
dongyi6269
dongyi6269
2016/02/06 19:26
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复