第一次海报,长时间读者所以对我温柔:)
请参阅以下代码,该代码用于生成财务年度中每月开始和结束的时间戳.
- 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);
- Long start = cal.getTimeInMillis();
- cal.clear();
- cal.set(earlyYear,1);
- lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
- cal.set(earlyYear,lastDayofMonth,23,59,59);
- Long end = cal.getTimeInMillis();
- }
- int[] lateMonths = {0,2,3,4,5,6,7}; // Jan to Aug
- for (int i : lateMonths) {
- month = i;
- Calendar cal = Calendar.getInstance();
- cal.clear();
- cal.set(year,0);
- Long start = cal.getTimeInMillis();
- cal.clear();
- cal.set(year,1);
- lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
- cal.set(year,59);
- Long end = cal.getTimeInMillis();
- }
到目前为止这么好,但是为了使用这些结果,我需要将这些时间戳输出到以月命名的变量(稍后在代码中用于预备语句.例如SeptStart = sometimestamp,SeptEnd = some timestamp等等.
我不知道是否可以根据每个循环的结果声明新变量.有任何想法吗?