dinesh707
dinesh707

Reputation: 12592

Why my date is not parsing

private final SimpleDateFormat gmailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");

But when i parse the date String "Thu, 25 Sep 2014 16:26:20 +0300" i get the following exception

java.text.ParseException: Unparseable date: "Thu, 25 Sep 2014 16:26:20 +0300"

Upvotes: 0

Views: 92

Answers (2)

santify
santify

Reputation: 106

The Date formatter is working fine. Make sure you are importing right package. See below the complete program

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {

    public static void main(String ap[])
    {
        SimpleDateFormat gmailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
        try {
            java.util.Date date = gmailDateFormatter.parse("Thu, 25 Sep 2014 16:26:20 +0300");
            System.out.println(date); 
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Output:

Thu Sep 25 06:26:20 PDT 2014

Upvotes: 0

Jens
Jens

Reputation: 69470

Add the Locale.ENGLISHas second parameter to the SimpleDateFormat constructor and it works:

private static  final SimpleDateFormat gmailDateFormatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);

Upvotes: 3

Related Questions