Here you go -- the interesting part is the while loop.

Chris

----------------------------------------
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class IncrementMonths {

    private static DateTimeFormatter DATE_FMT =
        DateTimeFormat.forPattern( "yyyy-MM-dd" );

    public static void main( final String ... args ) {
        if ( args.length != 2 ) {
            out( "Usage: java ... IncrementMonths start end" );
            out( " - Use: yyyy-MM-dd formats" );
            System.exit(1);
        }
        LocalDate currentDate = readDate( args[0] );
        final LocalDate endDate   = readDate( args[1] );
        while ( currentDate.isBefore( endDate ) ) {
            out( currentDate.toString( "MMMM yyyy" ) );
            currentDate = currentDate.plusMonths(1);
        }
    }

    private static LocalDate readDate( final String text ) {
        return new LocalDate( DATE_FMT.parseDateTime( text ) );
    }

    private static void out( final String msg ) {
        System.out.println( msg );
    }
}

----------------------------------------

Ivan Polak wrote:
> Hi, how to get a list of months between two dates (LocalDate) ?
> 
> for example, start date is 2.1.2010 (format : dd/mm/yyyy), and end
> date is 23.09.2010, i need list of months between 2.1.2010 -
> 23.09.2010 : February 2010, March 2010, April 2010, May 2010, June
> 2010, July 2010, August 2010, (September 2010 ?).
> 
> Thanks!
> 
> Ivan
> 
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to