问题描述
我收到此消息:
Invalid datetime "2017-11-07T19:46:57.118Z", expected format Y-m-d\\TH:i:sP.
使用JMS序列化程序和配置时:
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?
推荐答案
这是一个艰难的过程,我之前曾遇到过.我正在使用批注,因此我的修复程序看起来像:
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'
或者,如果jms读取yaml文件的方式与注释的方式不同,那么您可能必须在"TH"之前的位置添加另一个斜杠.
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.
这篇关于使用JMS序列化程序和ISO8601获得日期时间格式的不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!