public function convertToDateTime(string $string) : \DateTime
    {
        $string = trim($string);
        foreach ([$this->getLastGuessedFormat(), $this->guessDateFormat($string) ] as $format) {
            $date = $this->newDate((string) $format, $string);
            if ($date instanceof \DateTime) {
                $date->setTimezone($this->getTimezone());

                return $date;
            }
        }

        return $this->stringToDateTime($string);
    }
public function convertToDateTime(string $string) : \DateTime
    {
        $string = trim($string);
        foreach ([$this->getLastGuessedFormat(), $this->guessDateFormat($string) ] as $format) {
            $date = $this->newDate((string) $format, $string);
            if ($date instanceof \DateTime) {
                $date->setTimezone($this->getTimezone());

                return $date;
            }
        }

        return $this->stringToDateTime($string);
    }
public function convertToDateTime ( string $ string ) : \ DateTime { $ string = trim ( $ string ) ; foreach ( [ $ this -> getLastGuessedFormat ( ) , $ this -> guessDateFormat ( $ string ) ] as $ format ) { $ date = $ this -> newDate ( ( string ) $ format , $ string ) ; if ( $ date instanceof \ DateTime ) { $ date -> setTimezone ( $ this -> getTimezone ( ) ) ; return $ date ; } } return $ this -> stringToDateTime ( $ string ) ; }
Creates a DateTime instance for the given string. Default format is RFC2822
@param  string                   $string
@return \DateTime
Creates a DateTime instance for the given string . Default format is RFC2822