如何将字符串转换为日期(PHP)?

时间:2015-08-28 13:04:42

标签: php

我想将30.10.2014 15\:25\:24转换为30/Oct/2014 15:25:24。我这样试过......

$s = '30.10.2014 15\:25\:24';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);

...但我的结果是01.Jan.1970 01:00:00

1 个答案:

答案 0 :(得分:0)

因为strtotime返回FALSE,代码如下所示

$s = '30.10.2014 15\:25\:24';  //invalid format
$date = strtotime($s);
if($date===FALSE)  //if strtotime failed
{
    echo "strtotime failed";
}