简体   繁体   English

使用 jms 序列化程序和 ISO8601 获取日期时间格式的不匹配

[英]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 和配置时:

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'

Or you may have to add another slash in there before "TH" if jms reads yaml files differently than annotations. 或者,如果jms以不同于注释的方式读取yaml文件,则可能必须在“TH”之前添加另一个斜杠。

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_serializer:
handlers:
    datetime:
        default_format: 'Y-m-d\TH:i:s.uP'

Use 'Ymd\\TH:i:s.uP' if you want to serialize/deserialize joda DateTime如果要序列化/反序列化 joda DateTime,请使用 'Ymd\\TH:i:s.uP'

(using joda DateTimeConverter on the client) (在客户端使用 joda DateTimeConverter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM