Java examples for java.util:Month
get Month End Calendar
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static void main(String[] argv) throws Exception { int year = 2; int month = 2; System.out.println(getMonthEndCalendar(year, month)); }//from www.jav a 2 s.c o m private static Calendar getMonthEndCalendar(int year, int month) { Calendar result = Calendar.getInstance(); result.setTime(getMonthStart(year, month)); result.set(Calendar.DAY_OF_MONTH, result.getActualMaximum(Calendar.DAY_OF_MONTH)); return result; } public static Date getMonthStart(int year, int month) { return parseDate(String.valueOf(year) + month, "yyyyM"); } public static Date parseDate(String dateString, String format) { SimpleDateFormat formater = new SimpleDateFormat(); formater.applyPattern(format); formater.setLenient(false); try { return formater.parse(dateString); } catch (ParseException e) { return null; } } }