M4tchB0X3r
M4tchB0X3r

Reputation: 1531

SimpleDateFormat parsing troubles

I'm having trouble parsing a date that I'm trying to reformat. The SimpleDateFormat is giving me a real headache.

I'm getting this date from a news feed:

Wed, 06 Mar 2013 09:22:00 +0100

And I need to format it to this:

06.03.2013

I could just use a hashmap with all the months but I would like to use the SimpleDateFormat, since that's what it's for.

But I can't seem to find the right pattern.

Upvotes: 0

Views: 107

Answers (1)

CRUSADER
CRUSADER

Reputation: 5472

Try adding following code snippet:--

    //SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss +SSSS");
SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss +SSSS", Locale.ENGLISH);
        Date date = null;
        try {
            date = fmt.parse("Wed, 06 Mar 2013 09:22:00 +0100");//Hardcoded for your case...
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        SimpleDateFormat fmtOut = new SimpleDateFormat("dd.MM.yyyy");

        System.out.println("Date :-- " +fmtOut.format(date));

Upvotes: 1

Related Questions