generically parsing String to date

不羁的心 提交于 2019-12-20 04:12:26

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/7596052/generically-parsing-string-to-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!