Java Month Calculate getThisMonthEnd()

Here you can find the source of getThisMonthEnd()

Description

get This Month End

License

Open Source License

Declaration

public static String getThisMonthEnd() 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    public static String getThisMonthEnd() {
        String strY = null;//from   w ww .j a va 2s  . c  o m
        String strZ = null;
        boolean leap = false;
        Calendar localTime = Calendar.getInstance();
        int x = localTime.get(Calendar.YEAR);
        int y = localTime.get(Calendar.MONTH) + 1;
        if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
            strZ = "31";
        }
        if (y == 4 || y == 6 || y == 9 || y == 11) {
            strZ = "30";
        }
        if (y == 2) {
            leap = leapYear(x);
            if (leap) {
                strZ = "29";
            } else {
                strZ = "28";
            }
        }
        strY = y >= 10 ? String.valueOf(y) : ("0" + y);
        return x + "-" + strY + "-" + strZ;
    }

    public static boolean leapYear(int year) {
        boolean leap;
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                if (year % 400 == 0)
                    leap = true;
                else
                    leap = false;
            } else
                leap = true;
        } else
            leap = false;
        return leap;
    }
}

Related

  1. getMonthSpan(Date begin, Date end)
  2. getNextMonth(long date)
  3. getNextMonthExtention(Date dt, Long n)
  4. getNowMonth()
  5. getStartOfMonth(Calendar scal)
  6. getThisMonthStart()
  7. incrementMonth(long date, int increment)
  8. intToCalendarMonth(int month)
  9. isFirstOfMonth(long date)