Here you can find the source of getFirstDayOfNextMonth(Date date, boolean isFormatDate)
public static Object getFirstDayOfNextMonth(Date date, boolean isFormatDate)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { static public final String FORMAT_NORMAL = "yyyy-MM-dd HH:mm:ss"; public static Object getFirstDayOfNextMonth(Date date, boolean isFormatDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//www .j av a2 s. com calendar.set(Calendar.MONDAY, calendar.get(Calendar.MONTH) + 1); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); if (isFormatDate) return formatDate(getFirstDayOfMonth(calendar.getTime())); return getFirstDayOfMonth(calendar.getTime()); } public static String formatDate(Date date) { return format(date, FORMAT_NORMAL); } public static Date getFirstDayOfMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.DATE, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } public static String format(Date date, String format) { SimpleDateFormat sf = new SimpleDateFormat(format); sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); return sf.format(date); } public static String format(Timestamp date, String format) { SimpleDateFormat sf = new SimpleDateFormat(format); sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); return sf.format(date); } public static Date format(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } }