laravel 如何获得laravel刀片中唯一的小时和分钟?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45285628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the only hours and minutes in laravel blade?
提问by Soul Coder
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.
是的,我想我滥用了这个功能,有人可以帮我吗?我是 Laravel 的新手。任何帮助将不胜感激。
回答by Vincent Decaux
If your variable is a DateTime, you can use this :
如果您的变量是 DateTime,则可以使用以下命令:
{{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }}
Or simplest way (depends on your version) :
或最简单的方法(取决于您的版本):
{{ $calllog['delivery_date']->format('H:i:s') }}
回答by Alexey Mezenin
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()
.
您正在寻找将小时和分钟显示为字符串的解决方案,请使用format()
.
For example, this will return 02:12:
例如,这将返回 02:12:
{{ $calllog['delivery_date']->format('h:i') }}
And this will return 14:12:
这将返回 14:12:
{{ $calllog['delivery_date']->format('H:i') }}