0

here is my date String : "07SEP2014 00:00"

and this is the code that convert string to date :

new SimpleDateFormat("ddMMMyyyy HH:mm").parse(dateString);

and i'm getting parse exception. What i'm doing wrong?

9
  • Works fine when I tried it. Sun Sep 07 00:00:00 BST 2014 Commented Mar 10, 2015 at 9:30
  • Works fine for me too. Can you post the stack trace? Commented Mar 10, 2015 at 9:31
  • Above code works fine with JDK 6 & 7. See my answer. Commented Mar 10, 2015 at 9:33
  • works for me too DEMO Commented Mar 10, 2015 at 9:35
  • java.text.ParseException: Unparseable date: "07SEP2014 00:00" this is the stack trace there is noting more Commented Mar 10, 2015 at 9:39

3 Answers 3

1

Your Code works - as long as your System has a Locale where SEP = September. You could set the Locale to be sure about that:

Date result = new SimpleDateFormat("ddMMMyyyy HH:mm",Locale.ENGLISH).parse(dateString);
Sign up to request clarification or add additional context in comments.

Comments

0
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateParse {

    public static void main(String[] args) {

        String date = "07SEP2014 00:00";
        try {
            Date dateParse = new SimpleDateFormat("ddMMMyyyy HH:mm").parse(date);
            System.out.println(dateParse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}

Output :

Sun Sep 07 00:00:00 IST 2014

Comments

0

You need to customize your date format based on pattern. More details here on customizing it.

Edit: Case is important here. SEP should be like Sep

    SimpleDateFormat formatter=new SimpleDateFormat("ddMMMyyyy HH:mm");
    Date today = new Date();
    today.setMonth(8);
    String result = formatter.format(today);
    System.out.println(result);

Output: 10Sep2015 15:08

Edit 2: Your example is also working.

    SimpleDateFormat formatter=new SimpleDateFormat("ddMMMyyyy HH:mm");
    Date result = formatter.parse("07Sep2014 00:00");
    System.out.println(result.toString());

Output: Sun Sep 07 00:00:00 IST 2014

3 Comments

I've also tried to changed SEP to Sep but it didnt change anything. it gives me the same error
java.text.ParseException: Unparseable date: "07Sep2014 00:00"
@CengizDogan: I have parsed you date also in Edit 2. Your code also should work. Which Java version you are using?(This does not effect the output)

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.