Here you can find the source of getNextMonthFirstDay(T day)
public static <T extends Date> T getNextMonthFirstDay(T day)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static <T extends Date> T getNextMonthFirstDay(T day) { if (day == null) return null; Calendar calendar = Calendar.getInstance(); calendar.setTime(day);//from ww w. j av a 2 s.co m int month = calendar.get(Calendar.MONTH); calendar.set(Calendar.MONTH, month + 1); calendar.set(Calendar.DAY_OF_MONTH, 1); String datefor = format(calendar.getTime(), "yyyy-MM-dd"); Long mill = parseDate(datefor).getTime(); T another = (T) day.clone(); another.setTime(mill); return another; } /** * @param date * @param pattern: Date format pattern * @return */ public static final <T extends Date> String format(T date, String pattern) { if (date == null) return null; try { SimpleDateFormat df = new SimpleDateFormat(pattern); String result = df.format(date); return result; } catch (Exception e) { return null; } } public static final Date parseDate(String strDate) { Date date = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); date = dateFormat.parse(strDate); return date; } catch (Exception pe) { return null; } } /** * @param strDate * @param pattern * @return */ public static final Date parseDate(String strDate, String pattern) { SimpleDateFormat df = null; Date date = null; df = new SimpleDateFormat(pattern); try { date = df.parse(strDate); return date; } catch (Exception pe) { return null; } } }