Common java query by start date and end date
Common java query by start date and end date
Package com. crm. mess. util; import java. text. dateFormat; import java. text. parseException; import java. text. simpleDateFormat; import java. util. date; public class DateUtil {// @ Testpublic static String SEDate (String start, String end) throws ParseException {DateFormat format = new SimpleDateFormat ("yyyy/MM/dd HH: mm: ss "); DateFormat formatStr = new SimpleDateFormat (" yyyy/MM/dd "); int dayMis = 1000*60*60 * 24; // CreateTime = 2015/01/16 & EndTime = 2015/01/16 23:59:59 // if the date is blank, query all if (start = null | "". equals (start) & (end = null | "". equals (end) {return "" ;}// if the start date does not have an end date, query the time of the start date if (start! = Null &&! "". Equals (start) & (end = null | "". equals (end) {long endLong = formatStr. parse (start ). getTime () + dayMis-1; String endStr = format. format (new Date (endLong); System. out. println (endStr); return "CreateTime =" + start + "& EndTime =" + endStr ;} // if the end date does not have a start date, query the time of the end date if (start = null | "". equals (start) & (end! = Null &&! "". Equals (end) {long endLong = formatStr. parse (end ). getTime () + dayMis-1; String endStr = format. format (new Date (endLong); System. out. println (endStr); return "CreateTime =" + end + "& EndTime =" + endStr;} // if (start! = Null &&! "". Equals (start) & end! = Null &&! "". Equals (end) {long endLong = formatStr. parse (end ). getTime () + dayMis-1; String endStr = format. format (new Date (endLong); System. out. println (endStr); return "CreateTime =" + start + "& EndTime =" + endStr;} return "CreateTime =" + start + "& EndTime =" + end ;} public static void main (String [] args) throws ParseException {SEDate ("","");}}