/** * Obtains an instance of `ZonedDateTime` from a text string. * * Valid examples: * - `2007-12-03T10:15:30:45Z` * - `2007-12-03T10:15:30+01:00` * - `2007-12-03T10:15:30+01:00[Europe/Paris]` * * @param string $text The text to parse. * @param DateTimeParser|null $parser The parser to use, defaults to the ISO 8601 parser. * * @return ZonedDateTime * * @throws DateTimeException If the date is not valid. * @throws DateTimeParseException If the text string does not follow the expected format. */ public static function parse($text, DateTimeParser $parser = null) { if (!$parser) { $parser = IsoParsers::zonedDateTime(); } return ZonedDateTime::from($parser->parse($text)); }