Android Date Get getDaysOfCurMonth(final String time)

Here you can find the source of getDaysOfCurMonth(final String time)

Description

get Days Of Cur Month

Declaration

public static int getDaysOfCurMonth(final String time) 

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 };//w w  w  .j  ava2  s .c o 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. getDayOfWeek(Date date)
  2. getDayOfWeek(String date)
  3. getDayOfWeek(String year, String month, String day)
  4. getDayofWeekInMonth(String year, String month, String weekOfMonth, String dayOfWeek)
  5. getDaysOfCurMonth()
  6. getMonth(Date date)
  7. getTomorrowAtEight()
  8. getWeekOfDate(Date dt)
  9. getYear(Date date)