1

I have the following String

strDate = "Mon Jun 06 18:35:01 CEST 2016"

How can I convert that to a date in order to compare it with a date object?

I know that there is the following

DateFormat format = new SimpleDateFormat("dd-MMM-yy");
Date newDate = (Date) format.parse(date); 

but I still I cannnot gen up what is the appropriate format for the previous String.

I appreciate if someone could guide me.

Thanks a lot and BR

KostasA
  • 5,204
  • 6
  • 23
  • 29

2 Answers2

2

These are the symbols (copied from here):

Letter  Date or Time Component
G       Era designator
y       Year 
M       Month in year
w       Week in year
W       Week in month
D       Day in year
d       Day in month
F       Day of week in month
E       Day in week
a       Am/pm marker
H       Hour in day (0-23) 
k       Hour in day (1-24)
K       Hour in am/pm (0-11)
h       Hour in am/pm (1-12)
m       Minute in hour
s       Second in minute 
S       Millisecond
z       General time zone
Z       RFC 822 time zone

So the format of "Mon Jun 06 18:35:01 CEST 2016" should be:

"EEE MMM dd HH:mm:ss z yyyy"
meskobalazs
  • 15,741
  • 2
  • 40
  • 63
2

CEST is Central European Summer Time. It is the same as CET with daylight savings into effect.

Try out the following code stuffs using EEE MMM dd HH:mm:ss Z yyyy date format

DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
Date date = dateFormat.parse("Mon Jun 06 18:35:01 CEST 2016");
Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76