开发者

Converting date string to date

I'm trying to use strtotime to convert date strings in the format Jan 14th 2011 to the format 2011-01-开发者_StackOverflow社区14 but it's not working.

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');


Please, refer to here: http://www.php.net/manual/en/datetime.formats.date.php

AFAIK, strtotime parses an English textual date or time into a Unix timestamp.


strtotime or solutions like that would need a little bit of changes for each use case. If you want to go a little bit further and have a permanent solution to convert raw string dates into time formats you can check this project I did https://github.com/raimonbosch/date.extraction I'm using regular grammars to detect all kind of date formats.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜