首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎么在程序中统计两日期间的所有日期

2012-01-08 
如何在程序中统计两日期间的所有日期例如我要统计2007-05-01至2007-05-24中间的所有日期,统计结果为2007-0

如何在程序中统计两日期间的所有日期
例如   我要统计2007-05-01   至   2007-05-24中间的所有日期,统计结果为2007-05-01,2007-05-02,2007-05-03......一直到2007-05-24.每天的日期都要列出来,该程序如何计算呢?   谢谢大家!

[解决办法]
select * from table_name where item > to_date( ' "+ date.toLoaclString() + " ', 'yyyy-mm-dd hh24:mi:ss ') and item <to_date( ' "+ date.toLoaclString() + " ', 'yyyy-mm-dd hh24:mi:ss ')

在oracle中你可以这样写你的sql语句
[解决办法]
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd ");
String begin = "2007-05-01 ", end = "2007-05-24 ";
Calendar beginDate = new GregorianCalendar();
beginDate.setTime(df.parse(begin));
Calendar endDate = new GregorianCalendar();
endDate.setTime(df.parse(end));

while(!beginDate.after(endDate)){
System.out.println(df.format(beginDate.getTime()));
beginDate.add(Calendar.DATE, 1);
}

热点排行