开发者

How can I find out if a string is parseable with jodatimes DateTime constructor?

开发者 https://www.devze.com 2023-01-14 19:36 出处:网络
I need to determine if an input string input can be parsed by jodatimes DateTime constructor Datetime(Object instant) but I\'m not interested in creating the DateTi开发者_运维百科me object at this tim

I need to determine if an input string input can be parsed by jodatimes DateTime constructor Datetime(Object instant) but I'm not interested in creating the DateTi开发者_运维百科me object at this time.

Is there any way to check if the string is parseable beside calling the constructor and catch the possible exception?


ConvertManager.getInstance().getInstantConverter() is what the constructor uses to see if there is a matching converted. However, it also thrown an exception.

But I that constructor would only consult the ISODateTimeFormat. If you want to specify a custom format:

DateTimeFormatter dtf = DateTimeFormat.forPattern(format);
dtf.parseDateTime(dateTimeString);

Alas, again you'd have to catch an IllegalArgumentException

0

精彩评论

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