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

前端 未结 15 1274
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:39

    I haven't found a better solution. You can use explode(), preg_match_all(), etc.

    I have a static helper function like this

    class Date {
    
        public static function ausStrToTime($str) {
            $dateTokens = explode('/', $str);
            return strtotime($dateTokens[1] . '/' . $dateTokens[0] . '/' . $dateTokens[2]); 
    
        }
    
    }
    

    There is probably a better name for that, but I use ausStrToTime() because it works with Australian dates (which I often deal with, being an Australian). A better name would probably be the standardised name, but I'm not sure what that is.

提交回复
热议问题