Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java DATE Parsing

Tags:

java

parsing

I´m having a stupid problem with java.util.Date.

I have this line of code, but I don´t understand why this date is unparseable with this format.

public class TestTime {
    public static void main(String[] args) {
        final String DATE_FORMAT = "EEE MMM dd HH:mm:ss zzz yyyy";

        String date = "Sat Dec 31 10:00:00 CET 2011";
        SimpleDateFormat dFormat = new SimpleDateFormat(DATE_FORMAT);

        Date lDate = null;
        try {
            lDate = dFormat.parse(date);
        } catch (ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}
like image 333
migueloop Avatar asked Dec 04 '22 19:12

migueloop


1 Answers

If your system uses a locale other than English you need to use this constructor:

SimpleDateFormat(DATE_FORMAT,Locale.ENGLISH);

If this is not the problem, you should format a date using the same formatter and compare the output to your input string.

like image 96
stacker Avatar answered Dec 15 '22 01:12

stacker