PHP 将时间从 UTC (TZD) 格式转换为“正常”格式时间

发布于 2024-12-12 20:18:06 字数 291 浏览 5 评论 0原文

我有一个提要,它以这种格式提供时间(不是日期时间):“20:00:00.000+03:00

我需要将其转换为仅显示“20:00< /代码>” 我知道我可以使用 substr 并删除字符串的其余部分来做到这一点,但这看起来更像是一种 hack,让我想知道它是否会产生不好的结果。

我已经尝试过执行 date('H:m', strtotime("20:00:00.000+03:00")); 但它给了我 20:10 ? ?

I have a feed that gives me times (not datetimes) in this format: "20:00:00.000+03:00"

I need to convert it to display just "20:00"
I know that I can do it using substr and cutting out the rest of the string, but that seems more like a hack and makes me wonder if it can produce bad results.

I already tried doing date('H:m', strtotime("20:00:00.000+03:00")); but it gives me 20:10 ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月牙弯弯 2024-12-19 20:18:06

除了第一个参数之外,您做得正确:

date('H:i', strtotime("20:00:00.000+03:00"));

将输出您期望的结果。

You are doing it right, except for the first argument :

date('H:i', strtotime("20:00:00.000+03:00"));

Will output the result you are expecting for.

淡淡離愁欲言轉身 2024-12-19 20:18:06

不是H:m,而是H:i。检查日期格式

Not H:m, but H:i. check the date format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文