Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a String to Date [duplicate]

String that I want to parse:

Sun Nov 10 10:00:00 CET 2013

My code:

substrings = "Sun Nov 10 10:00:00 CET 2013"

SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM d HH:mm:ss ZZZ yyyy");
Date date = parserSDF.parse(substrings);

Compiler error output:

java.text.ParseException: Unparseable date: "Sun Nov 10 10:00:00 CET 2013" at java.text.DateFormat.parse(Unknown Source) ...

like image 650
Facon Avatar asked Mar 26 '26 05:03

Facon


1 Answers

Probably you are missing the correct Locale. Try this, in your example:

    SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM d HH:mm:ss ZZZ yyyy", Locale.US);
like image 75
Italo Borssatto Avatar answered Mar 27 '26 18:03

Italo Borssatto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!