Parsing a yyyy-MM-dd\'T\'HH:mm:ssZ date

Hi everyone. I know this is not really a cakephp problem and sorry for this, but anyone knows how to parse a date like 2016-05-20T09:00:000.000P?

When i created a new time object, that format works fine:

>>> $t = new Time('2016-05-20T09:00:00.000P')
=> Cake\I18n\Time {#222
     +"time": "2016-05-20T09:00:00-03:00",
     +"timezone": "P",
     +"fixedNowTime": false,
>>> $t->i18nFormat('yyyy-MM-dd HH:mm:ss','UTC')
=> "2016-05-20 12:00:00"

Now when i try to parse, i can’t extract the timezone part.

>>> Time::parseDateTime('2016-05-02T09:00:00.000P','yyyy-MM-dd\'T\'HH:mm:ss')
=> Cake\I18n\Time {#223
     +"time": "2016-05-02T09:00:00+00:00",
     +"timezone": "UTC",
     +"fixedNowTime": false,
>>> Time::parseDateTime('2016-05-02T09:00:00.000P','yyyy-MM-dd\'T\'HH:mm:ssZ')
=> null
>>> Time::parseDateTime('2016-05-02T09:00:00.000P',"yyyy-MM-dd'T'HH:mm:ss'Z'")
=> Cake\I18n\Time {#205
     +"time": "2016-05-02T09:00:00+00:00",
     +"timezone": "UTC",
     +"fixedNowTime": false,


If anyone wants to know why i need this, it is to use on the localizedTime validator:.

    ->add('date_created', 'validDate', [
        'rule' => ['localizedTime', 'datetime', 'yyyy-MM-dd\'T\'HH:mm:ss']

I’m not sure, but i think its a good idead to validate the timezone too.

Validating timezone is something new.
How about just adding it in models and let them do all the work? Also, check this link if you are worried about someone using inspect element.

Does it save in UTC? Check your bootstrap.php file and comment where it says date_default_timezone_set('UTC');
Also, under app.php under datasource, comment timezone key which is default to UTC.

Or maybe replace it with yours.

Hope it helps.

Thanks for your reply, but you see, its not really that i want to validate the time zone. The topic is about parse a date with a time zone, and i figure out what was missing.

parseDateTime uses the default time zone to parse the date. I just need to use date_default_timezone_set to fix the timezone before parse the date.