Failed to parse time string at position 41 (i): Double timezone specification

I would say this is a bug. You get the same error, when using this string

$dateStarted = new \DateTime("Thu Nov 15 2012 00:00:00 GMT-0700 (abcdefg)");

One less

$dateStarted = new \DateTime("Thu Nov 15 2012 00:00:00 GMT-0700 (abcdef)");

and it is parsed "properly".

It seems the time zone string is restricted to 6 characters. Unless you can and are willing to configure your Windows clients, I would say stripping the "time zone" is a viable "solution".


Using DateTime::createFromFormat() as Marc B suggested seems to be a better solution.

What I've ended up with is:

$dateStarted = \DateTime::createFromFormat('D M d Y H:i:s e+', $post['startDate']); // Thu Nov 15 2012 00:00:00 GMT-0700 (Mountain Standard Time)
print_r($dateStarted);
print_r(\DateTime::getLastErrors());

Which outputs the correct date now:

DateTime Object
(
    [date] => 2012-11-15 00:00:00
    [timezone_type] => 1
    [timezone] => -07:00
)

Array
(
    [warning_count] => 1
    [warnings] => Array
        (
            [33] => Trailing data
        )

    [error_count] => 0
    [errors] => Array
        (
        )

)

The + at the end of the format is the magic that makes this work.

Tags:

Php

Jquery