Java Month Get getWorkMonthLastDay(Date date)

Here you can find the source of getWorkMonthLastDay(Date date)

Description

get Work Month Last Day

License

Open Source License

Declaration

public static Date getWorkMonthLastDay(Date date) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getWorkMonthLastDay(Date date) {
        Calendar temp = Calendar.getInstance();
        temp.setTime(date);/*w ww .ja  v  a  2  s  .  c o  m*/
        int y = temp.get(Calendar.YEAR);
        int m = temp.get(Calendar.MONTH) + 1;
        int d = temp.get(Calendar.DAY_OF_MONTH);
        int ry = 0, rm = 0, rd = 0;
        if (d >= 1 && d <= 20) {
            rm = m;
            ry = y;
        }
        if (d >= 21) {
            if (m == 12) {
                ry = y + 1;
                rm = 1;
            } else {
                rm = m + 1;
                ry = y;
            }
        }
        rd = 20;
        String sj1 = String.valueOf(ry) + "-" + String.valueOf(rm) + "-" + String.valueOf(rd);
        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
        Date r_date = null;
        try {
            r_date = myFormatter.parse(sj1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return r_date;
    }
}

Related

  1. getThisMonthAndCycle()
  2. getThisMonthDate()
  3. getThisMonthLastDate()
  4. getTsOfMonth(Date date, boolean isEnd, boolean isPrevious)
  5. getWeekOfMonth(String datetime)
  6. getYesterdayOnLastMonth(String yesterday)
  7. getYestMonth()