作者:平凡2188 | 来源:互联网 | 2023-07-31 10:17
ImusingLaravel4tocreatemyproject.我正在使用Laravel4来创建我的项目。Iamcurrentlybuildingthecommen
I'm using Laravel 4 to create my project.
我正在使用Laravel 4来创建我的项目。
I am currently building the comments section and I want to display how long ago the post was created, kind of like Facebook's '10 mins ago' & '2 weeks ago' etc.
我现在正在构建评论部分,我想展示一下这个帖子是多久之前创建的,有点像Facebook的“10分钟前”和“两周前”等等。
I have done a little bit of research and found that a package called Carbon can do this.
我做了一些研究,发现一个叫做碳的包裹可以做到这一点。
After reading the Laravel doc's, it says:
读了拉拉维尔医生的书后,上面写着:
By default, Eloquent will convert the created_at
, updated_at
, and deleted_at
columns to instances of Carbon
, which provides an assortment of helpful methods, and extends the native PHP DateTime
class.
默认情况下,strate将created_at、updated_at和deleted_at列转换为Carbon实例,这提供了各种有用的方法,并扩展了本机PHP DateTime类。
But when I return a date column that I have created, it doesn't display it like on Facebook.
但当我返回我创建的日期列时,它不会像在Facebook上那样显示它。
The code that I'm using is:
我使用的代码是:
return array('time');
Has any body used this Carbon package that could give me a hand in doing what I need, I'm quite confused.
有没有人用过这个碳包可以帮助我做我需要的事,我很困惑。
5 个解决方案