Date List Increment Method in Java -


OK, so here's the question, I'm trying to make a method, which gives me all the dates date A

As the result should be

01-01-2013 Tuesday

02-01- 2013 Wednesday

03-01-2013 Thursday

And it should be in a map / list.

I have listed the following approach at least in the first list, but have received a Java Out of Heap Space error.

  public static list & lt; ShiftDate & gt; CreateShiftDate () {string startdate = "2013-01-01"; String last date = "2013-01-28"; SimpleDefformFormat = New SimpleDateform ("YYA-MM-DD"); & Lt; ShiftDate & gt; ShiftDateList = New Arreelist & amp; ShiftDate & gt; (); ShiftDate shiftDate = new ShiftDate (); Try {Date startDate1 = formatter.parse (startdate); Date expiration date = formatter.pars (end date); Calendar c = Calendar.getInstance (); Date new date = start date 1; While (newDate.compareTo (End date 1) & lt; 0) {c.setTime (newDate); C.add (calendar.date, 1); ShiftDate.setDateString (. C.getTime () toString ()); ShiftDateList.add (shiftDate); }} Hold (ParseException e) {e.printStackTrace (); } (ShiftDate shiftDate1: shiftDateList) {System.out.println (shiftDate1); } Return change date list; }  
  • You have the loop position variable ( newDate ). It should look like this:

      while newDate.compareTo (endDate1) & lt; 0) {c.setTime (newDate); C.add (calendar.date, 1); NewDate = c.getTime (); ShiftDate.setDateString (. C.getTime () toString ()); ShiftDateList.add (shiftDate); }  
  • Other problems: You have a formattor set for DD-MM-yyyy patter, but actual dates are in yyyy-MM-dd pattern

  • In addition to this, you will have to make a new instance of ShiftDate every time, or you will end up with the entire list every time or you will be the same (last updated) date value.

      while (newDate.compareTo (endDate1) & lt; 0) {c.setTime (newDate); C.add (calendar.date, 1); NewDate = c.getTime (); ShiftDate = new ShiftDate (); ShiftDate.setDateString (. C.getTime () toString ()); ShiftDateList.add (shiftDate); }  

  • Comments

    Popular posts from this blog

    ios - How do I use CFArrayRef in Swift? -

    eclipse plugin - Run java code error: Workspace is closed -

    c - Error on building source code in VC 6 -