Android Date Get getDaysOfCurMonth()

Here you can find the source of getDaysOfCurMonth()

Description

get Days Of Cur Month

Declaration

public static int getDaysOfCurMonth() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static int getDaysOfCurMonth() {
        int curyear = Integer.valueOf(getCurrentYear()).intValue();
        int curMonth = Integer.valueOf(getCurrentMonth()).intValue();
        int mArray[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
                30, 31 };//from  w  w  w.  j  av a  2s. co  m
        if ((curyear % 400 == 0)
                || ((curyear % 100 != 0) && (curyear % 4 == 0))) {
            mArray[1] = 29;
        }
        return mArray[curMonth - 1];
    }

    public static int getDaysOfCurMonth(final String time) {
        if (time.length() != 7) {
            throw new NullPointerException("yyyy-MM");
        }
        String[] timeArray = time.split("-");
        int curyear = Integer.valueOf(timeArray[0]).intValue();
        int curMonth = Integer.valueOf(timeArray[1]).intValue();
        if (curMonth > 12) {
            throw new NullPointerException("null pointer ");
        }
        int mArray[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
                30, 31 };
        if ((curyear % 400 == 0)
                || ((curyear % 100 != 0) && (curyear % 4 == 0))) {
            mArray[1] = 29;
        }
        if (curMonth == 12) {
            return mArray[0];
        }
        return mArray[curMonth - 1];
    }

    public static String getCurrentYear() {
        return getFormatCurrentTime("yyyy");
    }

    public static String getCurrentMonth() {
        return getFormatCurrentTime("MM");
    }

    public static String getFormatCurrentTime(String format) {
        return getFormatDateTime(new Date(), format);
    }

    public static String getFormatDateTime(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. getDateTomorrow(String date)
  2. getDayOfWeek(Date date)
  3. getDayOfWeek(String date)
  4. getDayOfWeek(String year, String month, String day)
  5. getDayofWeekInMonth(String year, String month, String weekOfMonth, String dayOfWeek)
  6. getDaysOfCurMonth(final String time)
  7. getMonth(Date date)
  8. getTomorrowAtEight()
  9. getWeekOfDate(Date dt)