使用 jms 序列化程序和 ISO8601 获取日期时间格式的不匹配 [英] Getting missmatch in datetime format using jms serializer and ISO8601

查看:11
本文介绍了使用 jms 序列化程序和 ISO8601 获取日期时间格式的不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这条消息:

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:

 @SerializerType("DateTime<'Y-m-dTH:i:s.uT'>")

所以我猜你的会是这样的:

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

jms_serializer:
    handlers:
        datetime:
            default_format: 'Y-m-dTH: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 获取日期时间格式的不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆