Parsing irregularly shaped date string in Java

In one sentence: Should I sort out "04 Dec 2014 1:58" from PrettyTime?

Descriptive: I need to parse and get the correct date format from an incorrect formatted date string. for example "04 December 2014 1:58". When I parse this example line, I get: "Thu Dec 04 02:59:33 ALMT 2014" which I believe is my current timestamp.

Consideration: If I only had this single bad format, I could write my own SimpleDateFormat. But there are good flavors of formatting that will generally be poorly formatted.

Can any of you tell me if I should expect PrettyTime to parse this type of poorly formatted string? Or could you point to some Java library that can handle these types of formatted date strings in Java?

+3


source to share


2 answers


Apparently after a few days of trying, my PrettyTime output is not capable of doing this, although it does handle some pretty good NLP date and time stuff. Finally I ended up with a simple SimpleDateFormat. Not the best solution, rather a temporary solution. If someone stumbles upon this topic, share your experience.



0


source


It 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();
        }

      

+1


source







All Articles