public static function parse($string)
    {

        // Current date and time
        if ($string == 'now' || empty($string)) {
            $date = new DateTime();

            // Timestamp
        } elseif (is_numeric($string)) {
            $date = new DateTime('@' . $string);

            // Attempt to parse the date provided against the Symphony configuration setting
            // in an effort to better support multilingual date formats. Should this fail
            // this block will fallback to just passing the date to DateTime constructor,
            // which will parse the date assuming it's in an American format.
        } else {
            // Standardize date
            // Convert date string to English
            $string = Lang::standardizeDate($string);

            // PHP 5.3: Apply Symphony date format using `createFromFormat`
            $date = DateTime::createFromFormat(self::$settings['datetime_format'], $string);

            if ($date === false) {
                $date = DateTime::createFromFormat(self::$settings['date_format'], $string);
            }

            // Handle dates that are in a different format to Symphony's config
            // DateTime is much the same as `strtotime` and will handle relative
            // dates.
            if ($date === false) {
                try {
                    $date = new DateTime($string);
                } catch (Exception $ex) {
                    // Invalid date, it can't be parsed
                    return false;
                }
            }

            // If the date is still invalid, just return false.
            if ($date === false || $date->format('Y') < 0) {
                return false;
            }
        }

        // Return custom formatted date, use ISO 8601 date by default
        return $date;
    }
public static function parse($string)
    {

        // Current date and time
        if ($string == 'now' || empty($string)) {
            $date = new DateTime();

            // Timestamp
        } elseif (is_numeric($string)) {
            $date = new DateTime('@' . $string);

            // Attempt to parse the date provided against the Symphony configuration setting
            // in an effort to better support multilingual date formats. Should this fail
            // this block will fallback to just passing the date to DateTime constructor,
            // which will parse the date assuming it's in an American format.
        } else {
            // Standardize date
            // Convert date string to English
            $string = Lang::standardizeDate($string);

            // PHP 5.3: Apply Symphony date format using `createFromFormat`
            $date = DateTime::createFromFormat(self::$settings['datetime_format'], $string);

            if ($date === false) {
                $date = DateTime::createFromFormat(self::$settings['date_format'], $string);
            }

            // Handle dates that are in a different format to Symphony's config
            // DateTime is much the same as `strtotime` and will handle relative
            // dates.
            if ($date === false) {
                try {
                    $date = new DateTime($string);
                } catch (Exception $ex) {
                    // Invalid date, it can't be parsed
                    return false;
                }
            }

            // If the date is still invalid, just return false.
            if ($date === false || $date->format('Y') < 0) {
                return false;
            }
        }

        // Return custom formatted date, use ISO 8601 date by default
        return $date;
    }
public static function parse ( $ string ) { // Current date and time if ( $ string == 'now' || empty ( $ string ) ) { $ date = new DateTime ( ) ; // Timestamp } elseif ( is_numeric ( $ string ) ) { $ date = new DateTime ( '@' . $ string ) ; // Attempt to parse the date provided against the Symphony configuration setting // in an effort to better support multilingual date formats. Should this fail // this block will fallback to just passing the date to DateTime constructor, // which will parse the date assuming it's in an American format. } else { // Standardize date // Convert date string to English $ string = Lang :: standardizeDate ( $ string ) ; // PHP 5.3: Apply Symphony date format using `createFromFormat` $ date = DateTime :: createFromFormat ( self :: $ settings [ 'datetime_format' ] , $ string ) ; if ( $ date === false ) { $ date = DateTime :: createFromFormat ( self :: $ settings [ 'date_format' ] , $ string ) ; } // Handle dates that are in a different format to Symphony's config // DateTime is much the same as `strtotime` and will handle relative // dates. if ( $ date === false ) { try { $ date = new DateTime ( $ string ) ; } catch ( Exception $ ex ) { // Invalid date, it can't be parsed return false ; } } // If the date is still invalid, just return false. if ( $ date === false || $ date -> format ( 'Y' ) < 0 ) { return false ; } } // Return custom formatted date, use ISO 8601 date by default return $ date ; }
Parses the given string and returns a DateTime object.

@since Symphony 2.3
@param string $string (optional)
A string containing date and time, defaults to the current date and time
@return DateTime|boolean
The DateTime object, or if the date could not be parsed, false.
Parses the given string and returns a DateTime object .