0

I''m trying to get a numerical representation of a date for the purpose of comparing two dates, so for example, if graduation date is > Start Date AND graduation Date < End Date - something like that.

I've had a look everywhere on stackoverflow and have not found anything that addresses my particular problem.

This is the error I'm currently getting:

 java.lang.IllegalArgumentException: Parse error: 2017-01-13
 at java.util.Date.parseError(Date.java:367)
 at java.util.Date.parse(Date.java:448)
 at java.util.Date.<init>(Date.java:157)

This is the code that I am running:

for(int i =0; i< ParseJSONNotif.getEC().length; i++) {
                        d[i] = pj.getDateConsumed()[i];
                    System.out.println("DATES ARE IN STRING FORMAT");
                    System.out.println("THESE ARE THE DATES: " + d[i]);;
                    Date ddj = new Date(d[i]);
                        ecdates[i] = ddj.getTime();
                    System.out.println("THESE ARE THE ECDATES: " + ecdates[i]);

The problem is obviously occurring on the following line: Date ddj = new Date(d[i]); As its unable to parse the following date: 2017-01-13

So how would i get a numerical representation/value for that date? As mentioned before, I need it for the purpose of comparing dates.

Thanks in advance!

1 Answers1

0

That constructor is deprecated, FYI. I think the problem is that your date is not in a format recognized by parse (which is also deprecated). https://docs.oracle.com/javase/7/docs/api/java/util/Date.html#parse(java.lang.String)

Use the newer DateFormat.parse instead. https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html

That should give you better control over which date formats are understood.

Brick
  • 3,998
  • 8
  • 27
  • 47