How do I get dates between two dates?

In the following example code I am going to get  dates between two dates. First, I need to convert the date value into milliseconds and increase startup date value from one date.

One date in milliseconds equlas to 24 * 60 * 60 * 1000L

import java.util.*;

public class DateUtil {
 static final long ONE_DAY = 24 * 60 * 60 * 1000L;

 public static void main(String[] args) {
  getDatesBetween("03/23/2011","03/28/2011");

 }

 public static void getDatesBetween(String startDate,String endDate) {


        long  from=Date.parse(startDate);  // long value of from date

        long to=Date.parse(endDate);     // long value of to date

        int x=0;

        while(from <= to) {
              x=x+1;
              System.out.println ("Dates  : "+new Date(from));
              from += ONE_DAY;
        }
        System.out.println ("No of Dates  :"+ x);


 }


}



Post a Comment

Popular posts from this blog

Yield Price Sri Lanka - Android Application

Manage SOAPAction of the Out Message

How to clean Registry log (REG_LOG) table