PHP 函数仅返回 DateTime 格式的日期
我有一个日期时间格式 '2022-03-17T15:00:00+02:00'
的字符串,我需要一个 php 函数来仅返回日期 '2022-03-17 '
。我没有找到解决办法。字符串 '2022-03-17T15:00:00+02:00'
在 xml feed 中是可变的。它每天都在变化,因此必须对其进行格式化以包含在函数中。
I have a string with the DateTime format '2022-03-17T15:00:00+02:00'
and I need a php function to return only the Date '2022-03-17'
. I didn't find a solution. The string '2022-03-17T15:00:00+02:00'
is variable in the xml feed. It change every day, so it must formatted to included in the function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
strtotime 不适合与 date 一起转换包含时区的日期,例如此处的 +02:00。与其他时区相关时可能会出现错误。示例:
亲自看看!
这里通常建议使用 DateTime,因为时区处理正确。
strtotime is not suitable in conjunction with date to convert a date that contains a time zone such as +02:00 here. Errors may occur in connection with other time zones. Example:
See for yourself!
The use of DateTime is generally recommended here, since the time zones are handled correctly.
https://www.php.net/manual/en/function.date。 php
https://www.php.net/manual/en/function.date.php
@Denis 和 @Relcode
该功能现在正常工作:
输出:2022-03-17
@Denis and @Relcode
That function now working properly:
Output: 2022-03-17