How do i convert a string time-stamp like "Thu Jun 07 13:01:59 IST 2007" to date format in java?
4 Answers
String ds = "Thu Jun 07 13:01:59 IST 2007";
SimpleDateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date d = f.parse(ds);
As others mentioned, the answer is in the docs.
1 Comment
dogbane
You should use
HH, not hh.First, create a date and time pattern string as specified in the SimpleDateFormat javadocs and then call parse to convert the string to a Date object.
1 Comment
alexey28
-1 not full answer. You should provide example in code
Use SimpleDateFormat. Something like this:
DateFormat fmt = new SimpleDateFormat("EEE MMM d hh:mm:ss Z yyyy");
Date date = fmt.parse(str);
1 Comment
dogbane
You should use
HH, not hh.
new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");