src/Sasedev/ExtraToolsBundle/Util/DateFormatter.php
private function parseTimestamp($date, $locale = null) {
        // try time default formats
        foreach ($this->formats as $timeFormat) {
            // try date default formats
            foreach($this->formats as $dateFormat) {
                $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $dateFormat, $timeFormat, date_default_timezone_get());
                $timestamp = $dateFormater->parse($date);

                if ($dateFormater->getErrorCode() == 0) {
                    return $timestamp;
                }
            }
        }

        // try other custom formats
        $formats = array(
            'MMMM yyyy', // november 2011 - nov. 2011
        );
        foreach($formats as $format) {
            $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $this->formats['none'], $this->formats['none'],  date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $format);
            $timestamp = $dateFormater->parse($date);

            if ($dateFormater->getErrorCode() == 0) {
                return $timestamp;
            }
        }

        throw new \Exception('"'.$date.'" could not be converted to \DateTime');
    }
private function parseTimestamp($date, $locale = null) {
        // try time default formats
        foreach ($this->formats as $timeFormat) {
            // try date default formats
            foreach($this->formats as $dateFormat) {
                $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $dateFormat, $timeFormat, date_default_timezone_get());
                $timestamp = $dateFormater->parse($date);

                if ($dateFormater->getErrorCode() == 0) {
                    return $timestamp;
                }
            }
        }

        // try other custom formats
        $formats = array(
            'MMMM yyyy', // november 2011 - nov. 2011
        );
        foreach($formats as $format) {
            $dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $this->formats['none'], $this->formats['none'],  date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $format);
            $timestamp = $dateFormater->parse($date);

            if ($dateFormater->getErrorCode() == 0) {
                return $timestamp;
            }
        }

        throw new \Exception('"'.$date.'" could not be converted to \DateTime');
    }
private function parseTimestamp ( $ date , $ locale = null ) { // try time default formats foreach ( $ this -> formats as $ timeFormat ) { // try date default formats foreach ( $ this -> formats as $ dateFormat ) { $ dateFormater = \ IntlDateFormatter :: create ( $ locale ? : \ Locale :: getDefault ( ) , $ dateFormat , $ timeFormat , date_default_timezone_get ( ) ) ; $ timestamp = $ dateFormater -> parse ( $ date ) ; if ( $ dateFormater -> getErrorCode ( ) == 0 ) { return $ timestamp ; } } } // try other custom formats $ formats = array ( 'MMMM yyyy' , // november 2011 - nov. 2011 ) ; foreach ( $ formats as $ format ) { $ dateFormater = \ IntlDateFormatter :: create ( $ locale ? : \ Locale :: getDefault ( ) , $ this -> formats [ 'none' ] , $ this -> formats [ 'none' ] , date_default_timezone_get ( ) , \ IntlDateFormatter :: GREGORIAN , $ format ) ; $ timestamp = $ dateFormater -> parse ( $ date ) ; if ( $ dateFormater -> getErrorCode ( ) == 0 ) { return $ timestamp ; } } throw new \ Exception ( '"' . $ date . '" could not be converted to \DateTime' ) ; }
Parse a string representation of a date to a timestamp.

@param string $date
@param string $locale
@return int Timestamp

@throws \Exception If fails parsing the string
Parse a string representation of a date to a timestamp .