取得昨天的日期 AND 日期大小比较

Calendar cal = Calendar.getInstance();
//取得昨天的日期
cal.add(Calendar.DATE,-1);
String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());

--------------------------------------
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
rs = st.executeQuery(sql);
rs.next();
if(rs.getString("endtime")!=null && !"".equals(rs.getString("endtime"))){
Date endtime = df.parse(rs.getString("endtime"));
Date today = df.parse(new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
//System.out.println(endtime);
//System.out.println(today);
if (endtime.getTime() < today.getTime()) {
flag = "over";
}
}else{
flag = "noendtime";
}
----------------------------------------

public static int compare_date(String DATE1, String DATE2) {
       
       
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() > dt2.getTime()) {
                System.out.println("dt1 在dt2前");
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                System.out.println("dt1在dt2后");
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;

你可能感兴趣的:(sql)