第一次发帖,长期读者,所以请对我温柔一些:)
请参阅以下代码,该代码可生成财政年度中每个月的开始和结束的时间戳。
int year = 2010;
// Financial year runs from Sept-Aug so earlyMonths are those where year = FY-1 and lateMonths are those where year = FY
int[] earlyMonths = {8, 9, 10, 11}; // Sept to Dec
int earlyYear = year -1;
for (int i : earlyMonths) {
month = i;
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(earlyYear,month,1,0,0,0);
Long start = cal.getTimeInMillis();
cal.clear();
cal.set(earlyYear,month,1);
lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
cal.set(earlyYear,month,lastDayofMonth,23,59,59);
Long end = cal.getTimeInMillis();
}
int[] lateMonths = {0, 1, 2, 3, 4, 5, 6, 7}; // Jan to Aug
for (int i : lateMonths) {
month = i;
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year,month,1,0,0,0);
Long start = cal.getTimeInMillis();
cal.clear();
cal.set(year,month,1);
lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
cal.set(year,month,lastDayofMonth,23,59,59);
Long end = cal.getTimeInMillis();
}
到目前为止一切顺利,但为了使用这些结果,我需要将这些时间戳输出到按月份命名的变量(将在代码中稍后的准备好的语句中使用。例如 SeptStart = 有时戳,SeptEnd = 一些时间戳等)。
我不知道是否可以根据每个循环的结果声明新变量。有任何想法吗?