public static List<String[]> analyseDate(int cycle,Date begintime,Date endtime){
List<String[]> results = new ArrayList<String[]>();
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
Calendar c3 = Calendar.getInstance();
c1.setTime(begintime);//2014-02-24
c2.setTime(endtime);//2015-04-30
String[] str =null;
String sd = "";
while(c1.compareTo(c2)<0){
// System.out.println(c1.getTime());
str = new String[2];
sd = c1.get(Calendar.YEAR)+"-"+(c1.get(Calendar.MONTH)+1)+"-"+c1.get(Calendar.DAY_OF_MONTH);
str[0]=sd;
if(c1.get(Calendar.MONTH)==2)
{
c1.add(Calendar.DAY_OF_YEAR, 1);
}
c1.add(Calendar.MONTH, 1);
c3.setTime(c1.getTime());
c3.add(Calendar.DAY_OF_YEAR,-1);
sd = c3.get(Calendar.YEAR)+"-"+(c3.get(Calendar.MONTH)+1)+"-"+c3.get(Calendar.DAY_OF_MONTH);
str[1] =sd;
// System.out.println("str[1]:"+str[1]);
results.add(str);
}
return results;
java计算两个日期之间的月 循环遍历
最新推荐文章于 2024-06-29 03:39:28 发布
本文介绍了一个用于分析指定日期范围内每月周期的Java工具。该工具通过输入开始和结束日期,能够生成每个月初和月末的日期列表,特别适用于财务结算或数据分析等场景中需要按月处理数据的情况。
2828

被折叠的 条评论
为什么被折叠?



