Here you can find the source of getSendTime(Date sendDate, Date start, Date end)
public static Date getSendTime(Date sendDate, Date start, Date end)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Date getSendTime(Date sendDate, Date start, Date end) { Calendar calendar = Calendar.getInstance(); if (sendDate != null) { calendar.setTime(sendDate);// w ww . jav a2 s .c om } Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(start); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(end); startCalendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); endCalendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); startCalendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)); endCalendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)); startCalendar.set(Calendar.DATE, calendar.get(Calendar.DATE)); endCalendar.set(Calendar.DATE, calendar.get(Calendar.DATE)); if (calendar.after(startCalendar) && calendar.before(endCalendar)) { return sendDate; } else if (calendar.before(startCalendar)) { return startCalendar.getTime(); } else { startCalendar.add(Calendar.DATE, 1); return startCalendar.getTime(); } } }