Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - convert CET string to Date [duplicate]

Tags:

java

datetime

I'm trying to convert this String to Date:

Tue Mar 01 11:46:32 CET 2016

this is the code I have:

DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date mTimeStamp = format.parse(getTimeStamp());

it throws a ParseExeption...

like image 881
Christer Avatar asked May 25 '26 04:05

Christer


1 Answers

Your format is fine - your issue may be that your default locale is not English and the day and/or month names are not valid in your default language.

This should work as expected:

DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date mTimeStamp = format.parse("Tue Mar 01 11:46:32 CET 2016");
like image 70
assylias Avatar answered May 26 '26 16:05

assylias