Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 ISO8601 序列化日期类型, 结果JSON串中缺少时区段,导致浏览器中获取的时间出错 #301

Closed
zlphoenix opened this issue Mar 2, 2015 · 2 comments

Comments

@zlphoenix
Copy link

按照https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 文档中关于日期时间的处理,序列化时通过SerializerFeature.UseISO8601DateFormat 指定序列化配置,应该序列化为"2015-03-02T16:59:11.621+08:00"的数据被序列化为"2015-03-02T16:59:11.621"
缺少时区后缀,在反序列化时会被认为是 UTC 时间.反序列化为 Js 对象后跟原始数据相差8小时.

@jarry
Copy link

jarry commented Mar 24, 2015

这个问题是时区造成的。前端JS只好做兼容:
// 北京为东8区时间,比伦敦时间早8小时,故需要加上8小时
// (传入毫秒 + 8 * 3600 * 1000);

或者在序列化时直接按照日期字符串转换,而不是拿到long型日期。
JSON.toJSONString(object, SerializerFeature.WriteDateUseDateFormat);

@wenshao
Copy link
Member

wenshao commented Apr 13, 2016

bug fixed. i will include in 1.2.9 & 1.1.49.android

@wenshao wenshao closed this as completed Apr 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants