一般解析字符串到日期
我正在与 Web 服务通信,并且 json 响应中包含日期。问题是这些日期的格式不同。有没有通用的方法来解析这些字符串?
I'm communication with a web service and it the json response has dates in it. the problem is those dates are in different formats. is there a generic way to parse these strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该有一个有序的格式列表来尝试(理想情况下使用 Joda Time 作为比内置的)并依次尝试每一个,直到其中一个起作用。它在性能方面并不理想(所有失败的例外情况),但它会起作用并且应该相当清晰。
当然,如果您可以联系网络服务提供商并建议他们返回标准格式,那就更干净了......
You should probably have an ordered list of formats to try (ideally using Joda Time as a far better API than the built-in one) and try each in turn until one works. It's not ideal in terms of performance (all the exceptions for failure) but it'll work and should be reasonably clear.
Of course, if you can get in touch with the web service provider and suggest that they return a standard format instead, that would be cleaner...