Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting missmatch in datetime format using jms serializer and ISO8601

I am getting this message:

Invalid datetime "2017-11-07T19:46:57.118Z", expected format Y-m-d\\TH:i:sP.

When using JMS Serializer and the config:

jms_serializer:
    handlers:
        datetime:
            default_format: 'Y-m-d\\TH:i:sP'

I think that my supplied date is in the correct format, but apparently not. Is it something that is wrong with the date?

like image 937
rablentain Avatar asked Nov 07 '17 14:11

rablentain


1 Answers

This is a tough one, I've run into it before. I was using annotations so my fix looked like:

 @Serializer\Type("DateTime<'Y-m-d\TH:i:s.uT'>")

So I'm guessing yours is going to look like:

jms_serializer:
    handlers:
        datetime:
            default_format: 'Y-m-d\TH:i:s.uT'

Or you may have to add another slash in there before "TH" if jms reads yaml files differently than annotations.

Can't remember exactly why this happens, I just remember trying a hundred different combinations until one worked. At any rate, dates and times are hard.

like image 177
Ollie in PGH Avatar answered Oct 28 '22 03:10

Ollie in PGH