public static int compare_date_after(Date DATE1, String DATE2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = DATE1;
// Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.after(dt2)) {
System.out.println("dt1 在dt2后");
} else {
System.out.println("dt1在dt2前");
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
public static void compare_date(Date DATE1, String DATE2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = DATE1;
Date dt2 = df.parse(DATE2);
if (dt1.getTime() > dt2.getTime()) {
System.out.println("dt1 在dt2后");
} else {
System.out.println("dt1在dt2前");
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String date = "2017-01-01 00:00:00";
compare_date(new Date(), date);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = DATE1;
// Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.after(dt2)) {
System.out.println("dt1 在dt2后");
} else {
System.out.println("dt1在dt2前");
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
public static void compare_date(Date DATE1, String DATE2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = DATE1;
Date dt2 = df.parse(DATE2);
if (dt1.getTime() > dt2.getTime()) {
System.out.println("dt1 在dt2后");
} else {
System.out.println("dt1在dt2前");
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String date = "2017-01-01 00:00:00";
compare_date(new Date(), date);
}
暂时先记载,以后遇到其他的再补上