How to get the only hours and minutes in laravel blade?

折月煮酒 提交于 2020-07-06 20:09:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!