惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - DataFlow

word break 在不同浏览器中的表现 系统架构 创造HTTPS的是个神 为Chrome开发插件提高工作效率 Javascript 控制style 小结 svcutil 生成代理类时的问题 xeam Build Definition Extension uninstall 卸载 Wcf客户端配置里Endpoint的Name属性无效 屏蔽电信流氓弹出广告 正则替换中的一个Bug SQL server 性能相关 SQL Express 相关 时间格式 输出一个在没有.Net 环境的机器也可以跑得安装包 再谈性能力 SCOM Configuration NumSamples and Absolute decimal.Round 的区别 Dos中常用的命令 反序列化怪现象,数组无父
XML中的时间
DataFlow · 2012-05-17 · via 博客园 - DataFlow

在SOA环境中,经常遇到时间,日期错乱的情况

明明在A端发的日期是2012-05-11,B端却收到2012-05-10, 什么情况?

原因在于

.net的反序列化会自动把DateTime类型的字段,转为本地时间

e.g.

         如果B所在的服务器,本地时区设置为太平洋时间 -7区:

        "2012-10-21"                      转化为         "2012-10-21 12:00:00 AM"

        "2012-10-21-07:00"             转化为         "2012-10-21 12:00:00 AM"

        "2012-10-21+00:00"            转化为         "2012-10-20 17:00:00 PM"

        "2012-10-21+08:00"            转化为         "2012-10-20 09:00:00 AM"

经过反序列化,21号就神奇地变成了20号

再经过下面的代码

date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture))

date.ToString("MM/dd/yyyy", DateTimeFormatInfo.InvariantInfo))

20就这样被传入了C端

原本以为上面的代码会转成UTC时间再tostring, 其实不会,跟不跟 CultureInfo.InvariantCulture都没有关系,时间不会变,变的只是格式,连接符

解决方案:

1. 设属性的类型为String, 不要使用DateTime类型,在发送前用

date.ToString("yyyy/MM/dd", DateTimeFormatInfo.InvariantInfo))转为String

接收方用:

Convert.ToDateTime(dateString, DateTimeFormatInfo.InvariantInfo);转为DateTime.

2. 使用DataContractSerializer, not XMLSerializer,前者在序列化时,不带时区

3 如果xsd已经确定,不能更改,属性的类型必须为DateTime,

发送前,先转为UTC时间,接收时 date.ToUniversalTime().ToString("yyyy/MM/dd", DateTimeFormatInfo.InvariantInfo))