2

My page sends a ajax request with payload:

start_date: "2014-07-03T21:37:01.396Z"

The date has been created with:

 var start_date = new Date();  

I've tried in the same way:

 var start_date = new Date().toISOstring;

The JMSSerializer needs this dateformat: Y-m-d\TH:i:sO. But is complaining:

"Invalid datetime \"2014-07-03T21:37:01.396Z\", expected format Y-m-d\\TH:i:sO."

My Entity-field has a annotation:

 @ORM\Column(name="start_date", type="datetime", nullable=true)

Type datetime comes from MySql DateTime.

erwineberhard
  • 309
  • 4
  • 17
  • 1
    I am having the same issue. From what I have read so far .396Z is the timezone offset in JS (396 minutes?). PHP is looking for the offset in the following format +HH:MM or +HHMM – Shawn Northrop Aug 09 '14 at 22:02

1 Answers1

2

I encountered the same problem. I ended up using moment.js: http://momentjs.com/

 var start_date = new Date();
 start_date = moment(start_date).format('YYYY-MM-DD[T]HH:mm:ssZZ');
Shawn Northrop
  • 5,826
  • 6
  • 42
  • 80
  • I found this post which gives an alternative solution by changing the expected format inside symfony: https://stackoverflow.com/questions/47160808/getting-missmatch-in-datetime-format-using-jms-serializer-and-iso8601 – Shawn Northrop Jul 12 '18 at 15:07