【问题标题】:Cakephp 3.7 Need mysql Time to be formatted but not the datetimeCakephp 3.7 需要 mysql 时间来格式化,但不是日期时间
【发布时间】:2019-10-09 08:45:03
【问题描述】:

在应用程序中,我在表中有 3 个字段

created(DateTime)
offer_start_time(time) 
offer_start_date(date)

分别具有价值

2019-10-06 06:01:21, 
00:15:00, 
2019-10-06

当我从数据库中获取记录时,我得到以下值

[created] => 06:01:21 
[offer_start_time] => 00:15:00
[offer_start_date] => 2019-10-06

所以在上面创建的值中缺少仅显示时间的日期。

以下是上述代码的 Bootstrap 配置

\Cake\I18n\FrozenDate::setJsonEncodeFormat('yyyy-MM-dd'); \Cake\I18n\Date::setJsonEncodeFormat('yyyy-MM-dd'); \Cake\I18n\FrozenTime::setJsonEncodeFormat('HH:mm:ss'); \Cake\I18n\Time::setJsonEncodeFormat('HH:mm:ss');
类型::build('time')->useImmutable(); 类型::build('date')->useImmutable(); 类型::build('datetime')->useImmutable(); 类型::build('timestamp')->useImmutable();

如果我更改,此问题适用于表中的所有日期时间列

\Cake\I18n\FrozenTime::setJsonEncodeFormat('HH:mm:ss');

\Cake\I18n\FrozenTime::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');

然后时间列开始显示日期,请告诉我如何解决这个问题

【问题讨论】:

标签: datetime cakephp cakephp-3.0


【解决方案1】:

检查这个例子:

created(DateTime)//use this  $created= date('Y-m-d H:m:s'); /// [created] => 2019-10-06 06:01:21
offer_start_time(time)//use this $offer_start_time = date(H:m:s'); /// [offer_start_time ] => 06:01:21
offer_start_date(date)//use this $offer_start_date = date('Y-m-d'); /// [offer_start_date] => 2019-10-06

【讨论】:

  • 这需要在使用上述值的每一段代码中完成,我需要 Cakephp 返回预期值的解决方案。这样就不需要更改控制器/视图。
猜你喜欢
  • 1970-01-01
  • 2020-11-21
  • 1970-01-01
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 2017-11-02
  • 2020-04-16
  • 1970-01-01
相关资源
最近更新 更多