strtotime函数不支持特定的日期格式


strtotime function doesnot support a specific date format

我正在使用具有特定日期格式的strtotime函数,但它还不起作用。

$gDate='30/04/2014';
echo strtotime($gDate);

这就是您应该在PHP 中使用DateTime类的原因

strtotime()返回长UNIX时间戳,在DateTime中返回其getTimestamp()

$gDate='30/04/2014';
$date = DateTime::createFromFormat('d/m/Y', $gDate);
echo $date->getTimestamp();

格式的日期

    $gDate='30/04/2014';

更改日期格式,使其可由strtotime函数使用

    $date = date_create_from_format('d/m/Y', $gDate);

echo-forate检查真正的格式echo$mydate=date_format($date,'Y-m-d'(;

给定日期上的strtotime函数

    echo $mystr = strtotime($mydate);

/*-strtotime仅适用于"Y-m-d"格式
*
*-采用m/d/y或d-m-y格式
*-如果分隔符是斜线(/(,则假定为美国m/d/y
*-如果分隔符是短划线(-(或点(.(,则假定为欧洲d-m-y格式
*
*
*-为了避免潜在的错误,您应该YYYY-MM-DD
**/