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

前端 未结 15 1117
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条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 09:36

    This workaround is simpler and more elegant than explode:

    $my_date = str_replace("/", ".", $my_date);
    $my_date = strtotime($my_date);
    $my_date = date("Y-m-d", $my_date);
    

    You don't have to know what format you're getting the date in, but if it comes with slashes they are replaced with full stops and it is treated as European by strtotime.

提交回复
热议问题