我有一个简单的网站与PHP和框架拉拉维尔。现在我只想显示日期,而不是时钟时间,当我在我的网站上发布我的文章时,它会根据笔记本电脑上的时钟显示时间和日期。我该怎么做?有推荐信吗?
这是我的密码:
<h6 class="date-comments"><i class="fa fa-user"></i> {{ ucwords($article->user->name) }} <i class="fa fa-calendar"></i> {{ date('d M Y', strtotime($article->created_at)) }} <i class="fa fa-comments"> {{ count($count) }}</i></h6>发布于 2018-03-21 06:36:16
class类是从PHP类继承的。
use Carbon\Carbonclass拥有从基类DateTime类继承的所有函数。这种方法允许您访问基本功能,如果您看到碳中缺少的任何东西,但在DateTime中。
class Carbon extends \DateTime { // code here }
特别注意确保正确处理时区,并在适当情况下基于底层DateTime实现。例如,所有比较都是在UTC或所使用日期时间的时区进行的。
$dtToronto = Carbon::create(2012, 1, 1, 0, 0, 0, 'America/Toronto');
$dtVancouver = Carbon::create(2012, 1, 1, 0, 0, 0, 'America/Vancouver')
echo $dtVancouver->diffInHours($dtToronto); // 3发布于 2018-03-21 04:38:16
使用laravel实用程序方法toDateString().Check下面的代码。
<h6 class="date-comments"><i class="fa fa-user"></i> {{ ucwords($article->user->name) }} <i class="fa fa-calendar"></i> {{ date('d M Y', strtotime($article->created_at->toDateString())) }} <i class="fa fa-comments"> {{ count($count) }}</i></h6>https://stackoverflow.com/questions/49398080
复制相似问题