【问题标题】:I want to store time as a hrs:min:sec Format in database and also display time as it is hrs:min:sec format我想将时间以 hrs:min:sec 格式存储在数据库中,并以 hrs:min:sec 格式显示时间
【发布时间】:2019-01-18 06:00:44
【问题描述】:

我使用时间数据类型来节省 db(mysql) 中的时间。
当我将时间存储在 db 中时,然后以 00:05:00.000000 格式保存,但我只想将 hrs:min:sec(00:05:00) 存储在 db 中。

还在我的前视图上显示 hrs:min:sec(00:05:00)。

【问题讨论】:

  • 所以在保存之前截断它。
  • 对我来说存储日期时间的最佳方式是时间戳,以后您可以将日期时间格式化为任何您想要的格式,而且速度更快
  • 完全是@Zeljka 写的,在显示之前格式化,不要重新发明自行车
  • 在将其保存到表之前进行数学运算
  • 你不存储格式,你存储时间,你在显示时格式化它。

标签: php mysql time


【解决方案1】:

$newtime = date("H:i:s", strtotime($this->time)); 试试这样

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-09
    • 2012-01-27
    • 2015-02-06
    • 2018-05-08
    • 2021-01-16
    • 2021-06-11
    • 2019-01-25
    • 1970-01-01
    相关资源
    最近更新 更多