Strtotime with European date format

后端 未结 5 2186
小蘑菇
小蘑菇 2021-01-06 22:02

I\'m trying to use strtotime to convert the following date:

07/09/2009 17:01:27

It\'s the Europe/London timezone format for 7th of September

The func

5条回答
  •  不知归路
    2021-01-06 22:20

    Here is a quick fix which should work. An alternative would be regex with named matches.

    function eurototime($string)
    {
        static $sorted = array(
            'tm_hour' => null,
            'tm_min' => null,
            'tm_sec' => null,
            'tm_mon' => null,
            'tm_mday' => null,
            'tm_year'  => null,
        );
        static $unsorted = array(
            'tm_mday',
            'tm_mon',
            'tm_year',
            'tm_hour',
            'tm_min',
            'tm_sec',
    
        );
        static $format = '%d/%d/%d %d:%d:%d';
        $parsed = sscanf($string, $format);
        $data = array_combine($unsorted, $parsed);
        $sortedData = array_merge($sorted, $data);
        $int = call_user_func_array('mktime', $sortedData);
        return $int;
    }
    
    date_default_timezone_set('Europe/London');
    echo eurototime(date('d/m/Y H:i:s')), "\n", time(),"\n";
    

提交回复
热议问题