Here you can find the source of getLastMonthAndCycle()
public static int[] getLastMonthAndCycle()
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static int[] getLastMonthAndCycle() { int[] o = new int[2]; String day = (getThisMonthAndCycle()[0] + "").substring(4, 6); int year = Integer.parseInt((getThisMonthAndCycle()[0] + "").substring(0, 4)); int month = getThisMonthAndCycle()[0]; int cycle = 0; if (getThisMonthAndCycle()[1] == 1) { if ("01".equals(day)) { year--;/*from w ww. j a va2 s . com*/ month = Integer.parseInt(year + "12"); } else { month--; } cycle = 3; } else { cycle = getThisMonthAndCycle()[1] - 1; } o[0] = month; o[1] = cycle; return o; } public static int[] getThisMonthAndCycle() { int cycle = 1; String str = new SimpleDateFormat("yyyyMMdd").format(new Date()); int month = Integer.valueOf(str.substring(0, 6)); int day = Integer.valueOf(str.substring(6, 8)); if (day <= 10) { cycle = 1; } if (day > 10 && day <= 20) { cycle = 2; } if (day > 20) { cycle = 3; } return new int[] { month, cycle }; } }