package com.lihan;
import java.util.*;
import java.text.*;
public class Test {
/**
* @author 李晗
* @param d1
* @param d2
* @return GregorianCalendar[]
* @throws ParseException
*/
public static GregorianCalendar[] getBetweenDate(String d1,String d2) throws ParseException
{
Vector<GregorianCalendar> v=new Vector<GregorianCalendar>();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar gc1=new GregorianCalendar(),gc2=new GregorianCalendar();
gc1.setTime(sdf.parse(d1));
gc2.setTime(sdf.parse(d2));
do{
GregorianCalendar gc3=(GregorianCalendar)gc1.clone();
v.add(gc3);
gc1.add(Calendar.DAY_OF_MONTH, 1);
}while(!gc1.after(gc2));
return v.toArray(new GregorianCalendar[v.size()]);
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
GregorianCalendar[] ga=getBetweenDate("2009-11-29", "2009-12-5");
for(GregorianCalendar e:ga)
{
System.out.println(e.get(Calendar.YEAR)+"年 "+
+(e.get(Calendar.MONTH)+1)+"月 "+
e.get(Calendar.DAY_OF_MONTH)+"号");
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lihan6415151528/archive/2009/01/19/3836644.aspx