Skip to content
Advertisement

Automatic Date/Time parser without specifying format [closed]

I am searching for a java library that can parse a string into a POJO without specifying the format. I have researched POjava. Is there anyother library which does similar thing?

DateTime dateTime = DateTimeParser.parse("21/02/13");

//If unclear use the cultural information passed
DateTime dateTime = DateTimeParser.parse("01/02/13", new Locale("en-us"));

//Should also work with time zones
DateTime dateTime = DateTimeParser.parse("2011/12/13T14:15:16+01:00");

I found the following links with the same problem Intelligent date / time parser for Java, but not very useful answers. Neither Joda or JChronic does what I wanted. Correct me if I am wrong.

Update:

The reason I say Joda does not solve my purpose is, Joda expects the string to be parsed in ISO8601 format or any format you specify like “yyyyMMdd”. I will not be able to hardcode this format as I need to handle several formats.

I have a hack around solution for eliminating the ambiguity with respect to American or European date formats, i.e. mm/dd/yy or dd/mm/yy. Assuming I have access to timezone of the date, can I determine if it is American or European format? Can someone tell me way to do this? Googled but found nothing.

Advertisement

Answer

I found the answer to my problem. I used this particular library POjava. This page explains how you can format the date+time string without specifying any format. However, for the library to work properly, you got to specify the date ordering like Day followed by Month or Month followed by Day.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement