How do i convert a string time-stamp like "Thu Jun 07 13:01:59 IST 2007" to date format in java?
Asked
Active
Viewed 9,922 times
4
-
1Can refer to [SimpleDateFormat](http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html) – Pau Kiat Wee May 08 '12 at 08:06
-
I don't get it to work so easily. Tried: `new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");` – juergen d May 08 '12 at 08:15
-
Please show your code, and the inputs and outputs – peter.murray.rust May 08 '12 at 08:16
4 Answers
4
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.

slipset
- 2,960
- 2
- 21
- 17
0
You can use DateFormat:
DateFormat dateFormat = new SimpleDateFormat("E M d HH:mm:ss z yyyy");
Date date = dateFormat.parse("Thu Jun 07 13:01:59 IST 2007");

alexey28
- 5,170
- 1
- 20
- 25
-1
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.

dogbane
- 266,786
- 75
- 396
- 414
-1
Use SimpleDateFormat
. Something like this:
DateFormat fmt = new SimpleDateFormat("EEE MMM d hh:mm:ss Z yyyy");
Date date = fmt.parse(str);

AlexR
- 114,158
- 16
- 130
- 208