get Last Day To Month From Number - Java java.util

Java examples for java.util:Month

Description

get Last Day To Month From Number

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        int year = 2;
        int month = 2;
        int day = 2;
        System.out.println(getLastDayToMonthFromNumber(year, month, day));
    }/*from   w  w  w . j  a v a 2  s.co m*/

    public static Calendar getLastDayToMonthFromNumber(int year, int month,
            int day) {
        return getCalendarFromNumber(year, month + 1, 0, 0);
    }

    public static Calendar getCalendarFromNumber(int year, int month,
            int day, int hour) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }
}

Related Tutorials