2

I get this from JQuery:

"Fri Nov 28 2014 10:19:52 GMT+0100 (CET)"

How do I format this String into a Date object in Java?

1 Answer 1

2

Try following code:

String date="Fri Nov 28 2014 10:19:52 GMT+0100 (CET)";
Date dateTime= new SimpleDateFormat("E MMM dd yyyy HH:mm:ss 'GMT'Z (z)").parse(date);

The dig is to use SimpleDateFormat to parse a String into Date. For more on SimpleDateFormat visit this link.

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

1 Comment

Funnily enough, I was using EEE MMM dd YYYY HH:mm:ss 'GMT'Z (z) but it gave me back Fri Jan 03 2014 10:19:52 GMT+0100 (CET). Your format string works properly if I use Locale.US at the end, because it breaks with my locale (Hungarian). Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.