Reputation: 305
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-HH.mm.ss", 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 ?
Upvotes: 0
Views: 192
Reputation: 5376
do like this.
String d=new SimpleDateFormat("dd.MM.yyyy").format(date);
System.out.println(d);
Upvotes: 0
Reputation: 10947
You are using capital Y
.
Try:
Date d_date = new SimpleDateFormat("dd.MM.yyyy-HH.mm.ss", Locale.ENGLISH).parse(s_date);
Upvotes: 2
Reputation: 35597
String s_date= ""13.06.2012-12.12.12";
this is wrong
use String s_date= "13.06.2012-12.12.12";
Upvotes: 0
Reputation: 9216
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.
Upvotes: 1
Reputation: 4634
You should add time as well:
new SimpleDateFormat("dd.MM.YYYY-HH.mm.ss", Locale.ENGLISH)
Upvotes: 2