Reputation: 171
I've searched a lot, but nothing seams to help me... I have built a string out of many resources that in the end looks like this (I have used some substring methods and things like that):
xxxa="16.Aug.2012 07:15:00"
and I want to parse it into date so I can compare it with current time. So, I use those lines:
Date datex=null;
DateFormat formatter = new SimpleDateFormat("dd.Mmm.yyyy hh:mm:ss");
try {
datex = (Date)formatter.parse(xxxa);
//Log.w("TIME: ", datex.toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
From my point of view, those 2 things match and should be parsed normaly.. or should it?
I always get an error like this:
java.text.ParseException: Unparseable date: "16.Aug.2012 07:00:00" at Java.text.DateFormat.parse(DateFormat.java:626) ........
I've tried to change positions of letters, to change where something will be.. but still does not fit. I can change that string to look like anything... I just want it to look like a real time, so I can compare time now and that time...
Anyone ??
Upvotes: 0
Views: 114
Reputation: 66637
As per SimpleDateFormat javadoc
M Month in year
m Minute in hour
String dateStr = "16.Aug.2012 07:15:00";
Date datex = null;
DateFormat formatter = new SimpleDateFormat("dd.MMM.yyyy hh:mm:ss");
try {
datex = (Date) formatter.parse(dateStr);
System.out.println(datex);
//Log.w("TIME: ", datex.toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 3