Laravel 4 Carbon日期格式仅更改一次 [英] Laravel 4 carbon date format change only once
本文介绍了Laravel 4 Carbon日期格式仅更改一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我要在应用程序页面上使用laravel 4,我喜欢碳日期功能,但是日期格式存在问题.我的日期格式如下:
Hello i am usng laravel 4 for a app page, i love the carbon date functions but i have a problem with a date format. i have the date format something like:
dd/mm/yyyy
我使用:
\Carbon\Carbon::createFromTimeStamp(strtotime(Auth::user()->created_at))->diffForHumans()
可以显示它的年代,但是当日期格式为
to show how old its something, but that works fine when the date format its
yyy-mm-dd
我怎么只能更改一次日期格式,而不是每次更改.
how can i only change one time the date format and not every time.
推荐答案
您可以尝试以下方法:
$date = Auth::user()->created_at;
\Carbon\Carbon::createFromFormat('d/m/Y', $date)->diffForHumans();
您也可以尝试使用此方法(如果您想使用createFromTimeStamp
方法):
Also you may try this (if you want to use createFromTimeStamp
method):
$date = str_replace('/', '-', Auth::user()->created_at);
\Carbon\Carbon::createFromTimeStamp(strtotime($date))->diffForHumans();
这篇关于Laravel 4 Carbon日期格式仅更改一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文