Strtotime() doesn't work with dd/mm/YYYY format

前端 未结 15 1121
Happy的楠姐
Happy的楠姐 2020-11-22 09:33

I really like the strtotime() function, but the user manual doesn\'t give a complete description of the supported date formats. strtotime(\'dd/mm/YYYY\')<

15条回答
  •  旧时难觅i
    2020-11-22 09:45

    Here is the simplified solution:

    $date = '25/05/2010';
    $date = str_replace('/', '-', $date);
    echo date('Y-m-d', strtotime($date));
    

    Result:

    2010-05-25
    

    The strtotime documentation reads:

    Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

提交回复
热议问题