【问题标题】:Why strtotime is not working appropriately?为什么 strtotime 工作不正常?
【发布时间】:2021-09-13 13:20:36
【问题描述】:

我想将代码 $txt 转换为 24 小时格式

$txt = "12:40:22AM";

echo date("G:i:s",strtotime($txt));

得到输出

0:40:22

【问题讨论】:

  • 你确定这是 strtotime 可以解析的格式吗?
  • 24 小时格式的午夜时间为 0 或 24。 12点应该是中午。 G 是 24 小时制,H 是 12 小时制。 php.net/manual/en/datetime.format.php
  • @aynber 我知道但只是想用 strtotime 测试它应该打印 12:40:22,而不是 0:40:22。
  • 12AM 是午夜,而不是中午! 12:40AM -> 00.40 和 12:40PM -> 12.40
  • @user1915746 我明白了我已经解决了我的问题。感谢您的宝贵时间!

标签: php date strtotime


【解决方案1】:

尝试在格式定义中使用 H 而不是 G。

$txt = "5:40:22AM";
$t = date("H:i:s",strtotime($txt));
echo $t;

【讨论】:

  • 谢谢你,我已经用 H 试过了,它正在处理我的问题陈述。
猜你喜欢
  • 1970-01-01
  • 2016-07-16
  • 2019-01-04
  • 2020-09-03
  • 2016-10-10
  • 2016-10-24
  • 2017-02-27
  • 2017-07-08
  • 2014-11-23
相关资源
最近更新 更多