Sou*_*der 3 php datetime laravel laravel-blade
我试图获得刀片中的小时,分钟和秒,通常我像下面这样使用
{{$calllog['delivery_date']}}
Run Code Online (Sandbox Code Playgroud)
但现在我的要求是获取小时,分钟和秒。这是我试图得到的
$calllog['delivery_date']->todatestring()}}
Run Code Online (Sandbox Code Playgroud)
是的,我想我误用了此功能,有人可以帮我吗?我是Laravel新手。任何帮助将不胜感激。
如果您的变量是DateTime,则可以使用以下命令:
{{ Carbon\Carbon::parse($calllog['delivery_date'])->format('H:i:s') }}
Run Code Online (Sandbox Code Playgroud)
或最简单的方法(取决于您的版本):
{{ $calllog['delivery_date']->format('H:i:s') }}
Run Code Online (Sandbox Code Playgroud)
如果您想获取分钟和小时作为单独的值:
{{ $calllog['delivery_date']->minute }}
{{ $calllog['delivery_date']->hour }}
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找将小时和分钟显示为字符串的解决方案,请使用format().
例如,这将返回 02:12:
{{ $calllog['delivery_date']->format('h:i') }}
Run Code Online (Sandbox Code Playgroud)
这将返回 14:12:
{{ $calllog['delivery_date']->format('H:i') }}
Run Code Online (Sandbox Code Playgroud)
http://carbon.nesbot.com/docs/
| 归档时间: |
|
| 查看次数: |
7015 次 |
| 最近记录: |