Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jodatime

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 DateTime object at this time.

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

like image 466
nj. Avatar asked Nov 20 '25 21:11

nj.


1 Answers

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

like image 172
Bozho Avatar answered Nov 22 '25 09:11

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!