Java Date Now getCurrentMonthLastDay()

Here you can find the source of getCurrentMonthLastDay()

Description

get Current Month Last Day

License

Apache License

Declaration

public static String getCurrentMonthLastDay() 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class Main {
    /**//from w  w  w .j  a v  a  2 s.  c  om
     * yyyy-MM-dd Comment for <code>onlyDateFmt</code>
     */
    public static final SimpleDateFormat onlyDateFmt = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    private static int monthDays[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    public static String getCurrentMonthLastDay() {
        String current = getCurrentStringDate();
        int year = Integer.parseInt(current.substring(0, 4));
        int month = Integer.parseInt(current.substring(5, 7));
        int day = getMonthDaysByYearMonth(year, month);
        return current.substring(0, 7) + "-" + day;
    }

    public static String getCurrentStringDate() {
        return onlyDateFmt.format(getCurrentDate());
    }

    public static int getMonthDaysByYearMonth(int year, int month) {
        if (month == 2) {
            GregorianCalendar gc = new GregorianCalendar();
            if (gc.isLeapYear(year))
                return monthDays[month - 1] + 1;
            else
                return monthDays[month - 1];
        } else
            return monthDays[month - 1];
    }

    public static Date getCurrentDate() {
        return new Date(System.currentTimeMillis());
    }
}

Related

  1. getCurrentMonth()
  2. getCurrentMonth()
  3. getCurrentMonth()
  4. getCurrentMonth(boolean bool, String currentDate)
  5. getCurrentMonthday()
  6. getCurrentMonthStartTime()
  7. getCurrentMonthString(Calendar calendar)
  8. getCurrentODSDate()
  9. getCurrentPlainDate()