将日期字符串转换为日期 [英] Converting date string to date
本文介绍了将日期字符串转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用 strtotime
将格式 2011年1月14日
的日期字符串转换为格式 2011-01-14
但它不工作。
I'm trying to use strtotime
to convert date strings in the format Jan 14th 2011
to the format 2011-01-14
but it's not working.
这种格式不适用于 strtotime
,如果是这样,我如何转换它。这个月一直是3个字母的格式,如1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月
Is this format not suitable for strtotime
and if so, how can I convert it. The month is always in 3-letter format, like Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
推荐答案
$date_str = "Jan 14th 2011";
$date = date_parse_from_format('M jS Y', $date_str);
echo $date->format('Y-m-d');
这篇关于将日期字符串转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文