get First Day Next Month From Number - Java java.util

Java examples for java.util:Month

Description

get First Day Next 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/*  w  w w .  ja  v a 2 s . co m*/
                .println(getFirstDayNextMonthFromNumber(year, month, day));
    }

    public static Calendar getFirstDayNextMonthFromNumber(int year,
            int month, int day) {
        return getCalendarFromNumber(year, month + 1, 1, 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