如何在PHP中获得给定日期或时间的格式?

发布于 2025-01-17 15:50:22 字数 156 浏览 1 评论 0原文

如何在PHP中获得给定日期或时间的格式?

如果我给出这样的日期,

2022-03-08 06:45:06

它应该返回“ ymd H:i:s”

是否有可能从日期开始获取格式的方法?

How to get a format of the given date or time in php?

If I give date like this,

2022-03-08 06:45:06

It should return "Y-m-d H:i:s"

Is there any possible way to get the format from date?

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

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

发布评论

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

评论(1

养猫人 2025-01-24 15:50:22

我不认为有这样的功能。

如果您需要处理不同格式的日期,请以时间戳重新格式化它们,然后以所需的格式

您可以尝试这样的操作

  $timestamp = strtotime("2022-03-08 06:45:06");
  $newFormat = date('Y-m-d', $timestamp)

i dont think there is such a function.

if you need to handle dates in different formats, reformat them in timestamp and then in the needed format

you can try something like this

  $timestamp = strtotime("2022-03-08 06:45:06");
  $newFormat = date('Y-m-d', $timestamp)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文