Java Month of Year getLastMonthAndCycle()

Here you can find the source of getLastMonthAndCycle()

Description

get Last Month And Cycle

License

Open Source License

Declaration

public static int[] getLastMonthAndCycle() 

Method Source Code

//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 };
    }
}

Related

  1. getFirstTimeOfDay(int year, int month, int day)
  2. getLastCompletedMonthAndYear()
  3. getLastMonth()
  4. getLastMonth()
  5. getLastMonth()
  6. getLastMonthdate()
  7. getLastMonthDate()
  8. getLastMonthDate(int date)
  9. getLastMonthOfQuater(Date date)