通常解析String到目前为止 [英] generically parsing String to date

查看:125
本文介绍了通常解析String到目前为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一个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?

推荐答案

你应该有一个有序的格式列表来尝试(理想情况下使用< a href =http://joda-time.sf.net =nofollow> Joda Time 作为一个比内置的更好的API)并逐个尝试,直到一个工作。它在性能方面并不理想(失败的所有例外),但它会起作用并且应该相当清楚。

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...

这篇关于通常解析String到目前为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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