generate dates between two date in Android

后端 未结 2 1248
面向向阳花
面向向阳花 2021-02-20 17:38

How to get all dates between two dates in Android.

For example. I have two Strings.

String first=\"2012-07-15\";  
String second=\"2012-07-21\"; 
         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 18:11

    public class DummyWorks extends Activity 
    {
    static final long ONE_DAY = 24 * 60 * 60 * 1000L;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        getDatesBetween("03/23/2011","03/28/2011");
    }
    
    public static void getDatesBetween(String startDate,String endDate) {
    
    
        long  from=Date.parse(startDate);  
    
        long to=Date.parse(endDate);  
    
        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);
    
    
     }
    }
    

提交回复
热议问题