Convert Date to UNIX timestamp

2019-01-19 00:44发布

问题:

I'm having a date format of Jun 26, '12.
strtotime() converts proper date string, and this string results in a blank output. This can be solved but I can only think of ugly ways of doing it.

Any ideas for converting this date format to UNIX timestamp elegantly?

回答1:

How about this strtotime('Jun 26,12');



回答2:

I used DateTime::createFromFormat works well for me.. more info here.



回答3:

Um, s/'/20/g'? Followed by strtotime()?



回答4:

Maybe something like this?

$string = 'April 26,\'12';
echo strtotime(preg_replace('/(\w+) (\d+),\'(\d+)/i', '$2 $1 20$3', $string));

Based on example from php.net