【问题标题】:Laravel 4 timestamp formatLaravel 4 时间戳格式
【发布时间】:2016-05-21 19:42:59
【问题描述】:

我正在使用 Laravel 4,我想显示 created_at。它是时间戳。 我这样显示-应该是这种格式-Y.m.d / h:i

但它显示错误的结果。数据库中的 created_at 列有值 -

2016-05-18 00:00:00

但是当我以这种方式显示它时,它会显示:

2016.05.18 / 12:00

@if($data->created_at !== '0000-00-00 00:00:00') 
{{date('Y.m.d / h:i', strtotime($data->created_at)) }}
@endif

【问题讨论】:

  • Y.m.d / h:i 应该是 Y.m.d / H:i 大写 H 24 小时时间。你也可以从使用 Laravel 内置的 Date mutators 中受益。

标签: laravel date timestamp


【解决方案1】:

Y-m-d H:i:s 是存储日期时间值的 ISO 格式,Laravel 一直在使用它 AFAIK。但是如果你使用 Eloquent 应该没问题,那么 created_atCarbon 日期时间,你可以通过调用 format() 方法来格式化它。 {{ $data->created_at->format('Y.m.d / H:i'); }}

【讨论】:

  • 是的,我正在使用 Laravel 时间戳,我应该如何检查 created_at 字段中是否有数据 - 我的意思是如果它不是 NULL 并且它不是那个值 -'0000-00- 00 00:00:00' ?这是好方法吗-> @if($data->created_at !== '0000-00-00 00:00:00' && $data->created_at )
猜你喜欢
  • 2016-02-13
  • 1970-01-01
  • 2011-12-04
  • 2016-07-12
  • 2019-02-17
  • 2017-05-23
  • 1970-01-01
相关资源
最近更新 更多