roundcubemail/program/lib/Roundcube/rcube_utils.php
public static function anytodatetime($date, $timezone = null)
    {
        if ($date instanceof DateTime) {
            return $date;
        }

        $dt   = false;
        $date = self::clean_datestr($date);

        // try to parse string with DateTime first
        if (!empty($date)) {
            try {
                $_date = preg_match('/^[0-9]+$/', $date) ? "@$date" : $date;
                $dt    = $timezone ? new DateTime($_date, $timezone) : new DateTime($_date);
            }
            catch (Exception $e) {
                // ignore
            }
        }

        // try our advanced strtotime() method
        if (!$dt && ($timestamp = self::strtotime($date, $timezone))) {
            try {
                $dt = new DateTime("@".$timestamp);
                if ($timezone) {
                    $dt->setTimezone($timezone);
                }
            }
            catch (Exception $e) {
                // ignore
            }
        }

        return $dt;
    }
public static function anytodatetime($date, $timezone = null)
    {
        if ($date instanceof DateTime) {
            return $date;
        }

        $dt   = false;
        $date = self::clean_datestr($date);

        // try to parse string with DateTime first
        if (!empty($date)) {
            try {
                $_date = preg_match('/^[0-9]+$/', $date) ? "@$date" : $date;
                $dt    = $timezone ? new DateTime($_date, $timezone) : new DateTime($_date);
            }
            catch (Exception $e) {
                // ignore
            }
        }

        // try our advanced strtotime() method
        if (!$dt && ($timestamp = self::strtotime($date, $timezone))) {
            try {
                $dt = new DateTime("@".$timestamp);
                if ($timezone) {
                    $dt->setTimezone($timezone);
                }
            }
            catch (Exception $e) {
                // ignore
            }
        }

        return $dt;
    }
public static function anytodatetime ( $ date , $ timezone = null ) { if ( $ date instanceof DateTime ) { return $ date ; } $ dt = false ; $ date = self :: clean_datestr ( $ date ) ; // try to parse string with DateTime first if ( ! empty ( $ date ) ) { try { $ _date = preg_match ( '/^[0-9]+$/' , $ date ) ? "@$date" : $ date ; $ dt = $ timezone ? new DateTime ( $ _date , $ timezone ) : new DateTime ( $ _date ) ; } catch ( Exception $ e ) { // ignore } } // try our advanced strtotime() method if ( ! $ dt && ( $ timestamp = self :: strtotime ( $ date , $ timezone ) ) ) { try { $ dt = new DateTime ( "@" . $ timestamp ) ; if ( $ timezone ) { $ dt -> setTimezone ( $ timezone ) ; } } catch ( Exception $ e ) { // ignore } } return $ dt ; }
Date parsing function that turns the given value into a DateTime object

@param string       $date     Date string
@param DateTimeZone $timezone Timezone to use for DateTime object

@return DateTime instance or false on failure
Date parsing function that turns the given value into a DateTime object