将日期 April/2019 转换为 04/2019
Convert date April/2019 to 04/2019
现在我有这样的约会,April/2019
。我想在 php 中将其转换为 04/2019
。如何解决?
date('m/Y', strtotime($_POST`['card_form_plan_start_date']))
What I Wanted - 04/2019
Actual Result - 01/1970
strtotime
won't recognise April/2019
as a date. Instead, you can use date_create_from_format
使用 F/Y
格式,然后将输出重新格式化为 m/Y
:
echo date_create_from_format('F/Y', 'April/2019')->format('m/Y');
输出
04/2019
您需要将 /
替换为 -
date('m/Y', strtotime(str_replace('/','-',$_POST`['card_form_plan_start_date'])))
现在我有这样的约会,April/2019
。我想在 php 中将其转换为 04/2019
。如何解决?
date('m/Y', strtotime($_POST`['card_form_plan_start_date']))
What I Wanted - 04/2019 Actual Result - 01/1970
strtotime
won't recognise April/2019
as a date. Instead, you can use date_create_from_format
使用 F/Y
格式,然后将输出重新格式化为 m/Y
:
echo date_create_from_format('F/Y', 'April/2019')->format('m/Y');
输出
04/2019
您需要将 /
替换为 -
date('m/Y', strtotime(str_replace('/','-',$_POST`['card_form_plan_start_date'])))