4

How do i convert a string time-stamp like "Thu Jun 07 13:01:59 IST 2007" to date format in java?

3
  • 1
    Can refer to SimpleDateFormat Commented May 8, 2012 at 8:06
  • I don't get it to work so easily. Tried: new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy"); Commented May 8, 2012 at 8:15
  • Please show your code, and the inputs and outputs Commented May 8, 2012 at 8:16

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You should use HH, not hh.
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");

2 Comments

-1 for using F. Should be E.
Should be yyyy, not YYYY. This will throw an exception.
-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.

1 Comment

-1 not full answer. You should provide example in code
-1

Use SimpleDateFormat. Something like this:

DateFormat fmt = new SimpleDateFormat("EEE MMM d hh:mm:ss Z yyyy");
Date date = fmt.parse(str);

1 Comment

You should use HH, not hh.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.