Java Month Day getMonthEndDay(String yyyy, String mm)

Here you can find the source of getMonthEndDay(String yyyy, String mm)

Description

get Month End Day

License

Apache License

Declaration

public static String getMonthEndDay(String yyyy, String mm) throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class Main {

    public static String getMonthEndDay(String yyyy, String mm) throws ParseException {
        if (yyyy == null || yyyy.trim().equals("")) {
            yyyy = getYear();/*  www . java 2 s  .  c  o m*/
        }

        if (mm == null || mm.trim().equals("")) {
            mm = getMonth();
        }

        int year = Integer.parseInt(yyyy);
        int month = Integer.parseInt(mm);
        int day = 0;

        String endDay = "";

        Calendar cal = new GregorianCalendar();
        cal.set(year, month, 0);

        year = cal.get(cal.YEAR);
        month = cal.get(cal.MONTH) + 1;
        day = cal.getActualMaximum(cal.DAY_OF_MONTH);

        endDay = year + String.format("%02d", month) + String.format("%02d", day);

        return endDay;
    }

    public static String getYear() throws ParseException {
        Date date = new Date();
        SimpleDateFormat formatter;
        String pattern = "yyyy";
        formatter = new SimpleDateFormat(pattern, new Locale("ko", "KOREA"));

        return formatter.format(date);
    }

    public static String getMonth() throws ParseException {
        Date date = new Date();
        SimpleDateFormat formatter;
        String pattern = "MM";
        formatter = new SimpleDateFormat(pattern, new Locale("ko", "KOREA"));

        return formatter.format(date);
    }
}

Related

  1. getLastMonthLastDay()
  2. getLastMothStart()
  3. GetLastWorkDayofMonth(String strDateStart)
  4. getMonthDay(int year, int month)
  5. getMonthEndDay(String time)
  6. getMonthFirstDay()
  7. getMonthFirstDay()
  8. getMonthFirstDay(Date date)
  9. getMonthFirstDay(String date)