aspose file tools*
The moose likes Java in General and the fly likes java.text.ParseException: Unparseable date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.text.ParseException: Unparseable date" Watch "java.text.ParseException: Unparseable date" New topic
Author

java.text.ParseException: Unparseable date

rajareddy annavaarm
Ranch Hand

Joined: Mar 15, 2007
Posts: 96
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

// df.format(new Date(properties.getProperty(
// df.format(new Date(properties.getProperty(calForm)
int iNoOfWorkingDays = 0;

do {
ss = calFrom.get(Calendar.YEAR) + "" + calFrom.get(Calendar.MONTH) + ""
+ calFrom.get(Calendar.DAY_OF_MONTH);

Date dd = new SimpleDateFormat().parse(ss);

ss = df.format(dd);
System.out.println("sadfsafsafsaf " + ss);
System.out.println("sadfsafsafsaf " + properties.getProperty(ss));

I am getting exception like below when I am executing above code

Exception in thread "main" java.text.ParseException: Unparseable date: "2007215"
at java.text.DateFormat.parse(Unknown Source)
at DateDifference.getDateDifferenceInDaysExcludingSatSun(DateDifference.java:175)
at DateDifference.main(DateDifference.java:51)

my property file is like this
200746=Good Friday
200712=New Years Day
200711=New Years Day
20071013=Hari Raya Puasa
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41580
    
  54
The problem is likely this line:



where you are creating a SimpleDateFormat without specifying which pattern it should use. I'm guessing that the default pattern it uses (whichever that may be) can't handle the "2007215" that you're throwing at it.

Actually, most patterns would have problems with that, because the month field is of varying length. You should use "20070215" instead.


Ping & DNS - my free Android networking tools app
rajareddy annavaarm
Ranch Hand

Joined: Mar 15, 2007
Posts: 96


I am getting exception like below

Exception in thread "main" java.text.ParseException: Unparseable date: "Thu Mar 15 11:40:11 GMT+05:30 2007"
at java.text.DateFormat.parse(Unknown Source)
at DateDifference.getDateDifferenceInDaysExcludingSatSun(DateDifference.java:171)
at DateDifference.main(DateDifference.java:51)


property file is like this

2007-10-13=Hari Raya Puasa
2007-12-25=Christmas Day
2007-08-09=National Day
rajareddy annavaarm
Ranch Hand

Joined: Mar 15, 2007
Posts: 96


I am getting exception like below

Exception in thread "main" java.text.ParseException: Unparseable date: "Thu Mar 15 11:40:11 GMT+05:30 2007"
at java.text.DateFormat.parse(Unknown Source)
at DateDifference.getDateDifferenceInDaysExcludingSatSun(DateDifference.java:171)
at DateDifference.main(DateDifference.java:51)


property file is like this

2007-10-13=Hari Raya Puasa
2007-12-25=Christmas Day
2007-08-09=National Day
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671


Why are you doing this? You start with a Calendar, you use getTime() to get a Date, then you use String.valueOf() to get a String and then use parse() to try to get a Date again? Why not just use the Date you had from getTime()? Surely that would be simpler.

The problem here is that String.valueOf() is calling toString(), and this is not formatting the date in the same format that your df object expects. Really, it would be best if you do not try to use String.valueOf() on a Date object, as you can't control the format used here. I can't see any reason why you would need it anyway.


"I'm not back." - Bill Harding, Twister
 
 
subject: java.text.ParseException: Unparseable date