简体   繁体   中英

Parsing ill-formated date-time string in Java

In one sentence: Should I be able to parse "04 Dec 2014 pm 1:58" by PrettyTime?

Descriptive: I am in need to parse & get proper date format from some ill formatted date-time string. eg "04 Dec 2014 pm 1:58". When I do parse this example string, I get : "Thu Dec 04 02:59:33 ALMT 2014" which is I believe my current time stamp.

Consideration: if I had only this single ill-format, I could write my SimpleDateFormat. But there can a good varieties of formatting which are mostly going to be ill-formatted.

Can any of you kindly tell me, whether should I expect PrettyTime to parse for this type of ill-formatted string? Or could you please point to any Java library which can handle these type of ill formatted date strings in Java?

This might help you!

SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy a hh:mm");
        String dateInString1 = "04 Dec 2014 pm 1:58";

        try {

            Date date = formatter.parse(dateInString1);
            System.out.println(date);
            System.out.println(formatter.format(date));

        } catch (ParseException e) {
            e.printStackTrace();
        }

Apparently, after days of various attempts, my finding is PrettyTime is not capable to do so though it handles pretty good NLP date & time related stuffs. Finally I ended up with various SimpleDateFormat . Not the best solution rather a temporary solution. If anyone stumble upon this thread, please share your experiences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM