简体   繁体   English

PHP strtotime不想工作

[英]PHP strtotime doesnt want to work

If I have the following code: 如果我有以下代码:

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

It returns false. 它返回false。 What is causing this? 是什么造成的?

That format is probably not a format that strtotime() can interpret. 该格式可能不是strtotime()可以解释的格式。 Try using DateTime::createFromFormat() instead: 尝试使用DateTime::createFromFormat()代替:

$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: 您的时间格式存在问题,strtotime肯定使用以下格式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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