get Days Of Month - Android java.util

Android examples for java.util:Month

Description

get Days Of Month

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {

    public static int getDaysOfMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, 1);//  
        calendar.roll(Calendar.DATE, -1);//  
        int maxDate = calendar.get(Calendar.DATE);
        return maxDate;
    }//from  ww  w  .  j  a  v  a 2  s. c om

    public static int getDaysOfMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, 1);//  
        calendar.roll(Calendar.DATE, -1);//  
        int maxDate = calendar.get(Calendar.DATE);
        return maxDate;
    }
}

Related Tutorials