PHP - 将字符串转换为各种日期格式
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
strtotime
函数与date
:只需调整
date
函数的格式参数即可获得您想要的格式的结果。您可能需要在转换日期格式后附加%
部分。You can use the
strtotime
function withdate
: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.您可以通过学习使用以下两个函数来做到这一点
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