Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all month names between two given date in java

Tags:

java

I need All month/Year names between two given date.I need this out put only on java.

Example :

Input Date:

    date 1- 20/12/2011 
    date 2- 22/08/2012

Now ,my expected result should be :- 

        Dec/2011
        Jan/2012
        Feb/2012
        Mar/2012
        Apr/2012
        May/2012
        Jun/2012
        Jul/2012
        Aug/2012

Could anybody help me. Thanks in Advance.

like image 675
JDGuide Avatar asked Aug 22 '12 08:08

JDGuide


1 Answers

Using Joda-Time (since not specified, I assume you could at least have a look at what joda time is):

 LocalDate date1 = new LocalDate("2011-12-12");
 LocalDate date2 = new LocalDate("2012-11-11"); 
 while(date1.isBefore(date2)){
     System.out.println(date1.toString("MMM/yyyy"));
     date1 = date1.plus(Period.months(1));
 }
like image 157
Eugene Avatar answered Sep 17 '22 22:09

Eugene