Query criteria Date time period is empty if the default setting is the month to tomorrow (0 o'clock), the query is less than tomorrow
String begindate=request.getparameter ("begindate");
String enddate=request.getparameter ("endDate");
if (! Commonmethod.isnull (begindate)) {
Qm.setbegindate (dateutil. Parsestringtodate(begindate, "yyyy-mm-dd"));
}else{
Qm.setbegindate (Dateutil.parsestringtodate (dateutil. Getformatdatestr(New Date (), "yyyy-mm") + " -01", "yyyy-mm-dd");
}
if (! Commonmethod.isnull (endDate)) {
Qm.setenddate (Dateutil.getnextndaydate (dateutil. Parsestringtodate(endDate, "Yyyy-mm-dd"), 1);
}else{
Qm.setenddate (dateutil. Getnextndaydate(New Date (), 1));
}
Use the function:
/**
* @ Function Description: Transform string to date
* @param datestr
* @return
* @ Create time 2008-7-13
* @author Administrator
*/
public static Date parsestringtodate (String datestr, String formate)
throws Exception {
try {
simpledateformat SDF = Getsimpledateformat (formate);
return Sdf.parse (DATESTR);
} catch (Exception ex) {
return null;
}
}
/**
* Get current date
* @return
* @throws Exception
*/
public static Date GetC Urrentdate () throws Exception {
date currtime = new Date (System.currenttimemillis ());
return Currtime;
}
/**
* get date n days after date
* @param date
* @param day
* @return
*
public Static Date getnextndaydate (date date, int day) {
calendar c=calendar.getinstance ();
c.settime (date);
c.add (Calendar.date, day);
// long d = date.gettime ();
// long n = day * 24 * 60 * 60 * 1000;
// d = d + N;
return c.gettime ();
}
/** * @ Function Description: Gets the string in the specified format * @return * @ creation Time 2008-7-26 * @author Beedoor */public static string Getformatdatestr (O Bject obj, String format) throws Exception {Date d = null; SimpleDateFormat SDF = getsimpledateformat (format); if (obj instanceof String) {d = Sdf.parse (Obj.tostring ()); } else if (obj instanceof date) {d = (date) obj;
} if (null! = d) {return Sdf.format (d); }
Return ""; }
Java Date Processing