convert "01-Apr-08.12:38:04" to Date object

Discussion in 'Java' started by mike, Apr 22, 2014.

  1. mike

    mike Guest


    How can I convert this:

    String time = "01-Apr-08.12:38:04";

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy'.'hh:mm:ss ");

    try {
    Date date = dateFormat.parse(time);
    } catch (ParseException e) {


    I get the following:

    java.text.ParseException: Unparseable date: "01-Apr-08.12:38:04"
    at java.text.DateFormat.parse(

    Any ideas on how I can work around this?

    mike, Apr 22, 2014
    1. Advertisements

  2. mike

    Eric Sosman Guest

    As you've constructed it, `dateFormat' requires a trailing space,
    but `time' doesn't have one.

    Also, I'm not too sure that using "hh" without an AM/PM indicator
    is a good idea. It's possible that parse() objects to the ambiguity.
    Eric Sosman, Apr 22, 2014
    1. Advertisements

  3. mike

    mike Guest

    Den tisdagen den 22:e april 2014 kl. 15:03:42 UTC+2 skrev Eric Sosman:

    yes I unintentionally added a space at the end and of course I should use HH.

    Thanks alot.

    mike, Apr 22, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.