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

前端 未结 15 1115
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:43

    This is a good solution to many problems:

    function datetotime ($date, $format = 'YYYY-MM-DD') {
    
        if ($format == 'YYYY-MM-DD') list($year, $month, $day) = explode('-', $date);
        if ($format == 'YYYY/MM/DD') list($year, $month, $day) = explode('/', $date);
        if ($format == 'YYYY.MM.DD') list($year, $month, $day) = explode('.', $date);
    
        if ($format == 'DD-MM-YYYY') list($day, $month, $year) = explode('-', $date);
        if ($format == 'DD/MM/YYYY') list($day, $month, $year) = explode('/', $date);
        if ($format == 'DD.MM.YYYY') list($day, $month, $year) = explode('.', $date);
    
        if ($format == 'MM-DD-YYYY') list($month, $day, $year) = explode('-', $date);
        if ($format == 'MM/DD/YYYY') list($month, $day, $year) = explode('/', $date);
        if ($format == 'MM.DD.YYYY') list($month, $day, $year) = explode('.', $date);
    
        return mktime(0, 0, 0, $month, $day, $year);
    
    }
    

提交回复
热议问题