简体   繁体   中英

PHP strtotime doesnt want to work

If I have the following code:

var_dump(strtotime('2:28:15am 28/11/2013'));

It returns false. What is causing this?

That format is probably not a format that strtotime() can interpret. Try using DateTime::createFromFormat() instead:

$dt = DateTime::createFromFormat('g:i:sa d/j/Y', '2:28:15am 28/11/2013');
echo $dt->format('Y-m-d H:i:s');

I had to guess at the exact formatting of your dates. But you can easily edit that by using the appropriate formatting options listed here .

There is a problem with your time format, strtotime works with the following format for sure:

$date->format('Y-m-d G:i:s');
strtotime($date);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM