问题
I am trying to get hours and minutes and seconds in blade, normally I use like below
{{$calllog['delivery_date']}}
but now my requirement is to get hours and minutes and seconds. here is how I tried to get
$calllog['delivery_date']->todatestring()}}
Yeah, I think I misuse for this function, can someone help me out? I am new in Laravel. Any help would be greatly appreciated.
回答1:
If your variable is a DateTime, you can use this :
{{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }}
Or simplest way (depends on your version) :
{{ $calllog['delivery_date']->format('H:i:s') }}
回答2:
If you want to get minutes and hours as separate values:
{{ $calllog['delivery_date']->minute }}
{{ $calllog['delivery_date']->hour }}
You you're looking for solution to show hours and minutes as a string, use format()
.
For example, this will return 02:12:
{{ $calllog['delivery_date']->format('h:i') }}
And this will return 14:12:
{{ $calllog['delivery_date']->format('H:i') }}
http://carbon.nesbot.com/docs/
来源:https://stackoverflow.com/questions/45285628/how-to-get-the-only-hours-and-minutes-in-laravel-blade