Java common query processing 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");D ateformat form Atstr = new SimpleDateFormat ("YYYY/MM/DD"); int daymis = + * * 24;////createtime=2015/01/16&endtime=2015/01 /16 23:59:59//If the date is empty query all if (start = = NULL | | ". Equals (Start)) && (end = = NULL | |" ". Equals (end)) {return "";} If the start date has an end date, then the query starts on the day of the time 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 has a start date, then the query ends on the day of the time 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;} Normal Date Query 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 ("", "");}}
Java common query processing by start date and end date