PHP - 将字符串转换为各种日期格式

发布于 2024-09-13 02:59:58 字数 143 浏览 4 评论 0原文

我是 PHP 新手,无法找出从 URL 参数转换两个字符串的最佳方法。

我想转换: “2010 年 8 月”至 ---> “2010-08-%”

以及: “2010”到---> “2010-%-%”

先谢谢您了!

I am new to PHP and cannot figure out the best method to convert two strings I have from URL params.

I would like to convert:
"August 2010" to ---> "2010-08-%"

and also:
"2010" to ---> "2010-%-%"

Thank you in advance!

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

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

发布评论

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

评论(2

晚雾 2024-09-20 02:59:58

您可以将 strtotime 函数与 date

echo date('Y-m', strtotime('August 2010'));

只需调整 date 函数的格式参数即可获得您想要的格式的结果。您可能需要在转换日期格式后附加 % 部分。

You can use the strtotime function with date:

echo date('Y-m', strtotime('August 2010'));

Just adjust the format parameter to the date function to get the result in the format you are looking for. You might want to append the % part after convert the date format.

吹泡泡o 2024-09-20 02:59:58

您可以通过学习使用以下两个函数来做到这一点
strtotime http://php.net/manual/en/function.strtotime.php
日期
http://php.net/manual/en/function.date.php

You can do those by learn to using these 2 following functions
strtotime http://php.net/manual/en/function.strtotime.php
date http://php.net/manual/en/function.date.php

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