0

I have a 'Fri Jan 16 08:41:11 GMT 2015' datetime string in my database.

I would like to parse it as a mysql datetime format String.

I am trying the code below, but getting

java.text.ParseException: Unparseable date: "Fri Jan 16 08:41:11 GMT 2015".

Code is:

String date = null;
if(pos.get("utc") != null) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        Date parsed = sdf.parse("Fri Jan 16 08:41:11 GMT 2015");
        date = sdf.format(parsed);
    } catch (JSONException | ParseException e) {
        e.printStackTrace();
    }
}

Any suggestions would be appreciated.

1
  • 4
    Look at your DateFormat pattern. Does it match your date String? Commented Jan 19, 2015 at 10:39

2 Answers 2

1

Try this SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy"); Reference

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

Comments

0

Thanks for the help :-)

String date = null;
if(pos.get("utc") != null) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
        Date parsed = sdf.parse("Fri Jan 16 08:41:11 GMT 2015");
        date = sdf.format(parsed);
    } catch (JSONException | ParseException e) {
        e.printStackTrace();
    }
}

Comments

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.