转换日期为四月2019年至四月2019年

时间:2019-02-13 10:59:03

标签: php date strtotime

现在我有这样的约会,April/2019。我想将其转换为php中的04/2019。该如何解决?

date('m/Y', strtotime($_POST`['card_form_plan_start_date']))
  

我想要什么-04/2019   实际结果-01/1970

2 个答案:

答案 0 :(得分:3)

strtotime无法将April/2019识别为日期。相反,您可以使用F/Y格式的date_create_from_format,然后将输出重新格式化为m/Y

echo date_create_from_format('F/Y', 'April/2019')->format('m/Y');

输出

04/2019

Demo on 3v4l.org

答案 1 :(得分:2)

您需要将/替换为-

 date('m/Y', strtotime(str_replace('/','-',$_POST`['card_form_plan_start_date'])))
相关问题