Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My date string is like this dd.MM.yyyy-HH.mm.ss . I am doing following:

String s_date= ""13.06.2012-12.12.12"
Date d_date = new SimpleDateFormat("dd.MM.YYYY", Locale.ENGLISH).parse(s_date); 

But it is throwing Unparseable date: "13.06.2012-12.12.12" Exception.

How can I make it work for the given date-time format ?

share
That actually doesn't throw an exception for me - which surprises me, given that you haven't provided any time parts in your format string... – Jon Skeet 6 mins ago

3 Answers

You should add time as well:

 new SimpleDateFormat("dd.MM.YYYY-HH.mm.ss", Locale.ENGLISH)
share

String s_date= "13.06.2012-12.12.12" doesn't fit your pattern dd.MM.YYYY. You should remove the part after the - if you want date without hours:

s_date = s_date.substring(0, s_date.indexOf('-'));

or change your pattern as Michał said.

share

Change to this

String s_date= ""13.06.2012-12.12.12"
Date d_date = new SimpleDateFormat("dd.MM.YYYY-HH.mm.ss", Locale.ENGLISH).parse(s_date);
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.