PHP date_format():如何从字符串值格式化日期

mps*_*hat 4 php date-format

我有一些PHP代码:

$exd = date_create('01 Dec, 2015');
$exd = date_format($exd, 'Y-m-d');
echo $exd;
Run Code Online (Sandbox Code Playgroud)

用于格式化日期.预期的输出将是2015-12-01但它会返回2016-12-01.我错过了什么?

Kev*_*vin 8

createFromFormat首先使用方法,提供输入格式:

$exd = DateTime::createFromFormat('d M, Y', '01 Dec, 2015');
// arguments (<format of the input>, <the input itself>)
$exd = date_format($exd, 'Y-m-d'); // then choose whatever format you like
echo $exd;
Run Code Online (Sandbox Code Playgroud)