开发者

generically parsing String to date

I'm communication with a web service and it the json response has dates in it. the problem is thos开发者_StackOverflowe dates are in different formats. is there a generic way to parse these strings?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜