Java??α??????????
???????????? ???????[ 2017/6/9 11:10:15 ] ??????????????????? Java
???????????Java????????????????????????
????Date.compareTo()
???????????????????????????????
????public static void main(String[] args) throws ParseException {
????SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
????Date date1 = sdf.parse("2009-12-31");
????Date date2 = sdf.parse("2010-01-31");
????System.out.println(sdf.format(date1));
????System.out.println(sdf.format(date2));
????if (date1.compareTo(date2) > 0) {
????System.out.println("Date1 is after Date2");
????} else if (date1.compareTo(date2) < 0) {
????System.out.println("Date1 is before Date2");
????} else if (date1.compareTo(date2) == 0) {
????System.out.println("Date1 is equal to Date2");
????} else {
????System.out.println("How to get here?");
????}
????}
????Date.before()?? Date.after() and Date.equals()
?????????????????????????????????????
????public static void main(String[] args) throws ParseException {
????SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
????Date date1 = sdf.parse("2009-12-31");
????Date date2 = sdf.parse("2010-01-31");
????System.out.println(sdf.format(date1));
????System.out.println(sdf.format(date2));
????if (date1.after(date2)) {
????System.out.println("Date1 is after Date2");
????}
????if (date1.before(date2)) {
????System.out.println("Date1 is before Date2");
????}
????if (date1.equals(date2)) {
????System.out.println("Date1 is equal Date2");
????}
????}
????Calender.before()?? Calender.after() and Calender.equals()
????????????????????????java.util.Calendar??
????public static void main(String[] args) throws ParseException {
????SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
????Date date1 = sdf.parse("2009-12-31");
????Date date2 = sdf.parse("2010-01-31");
????System.out.println(sdf.format(date1));
????System.out.println(sdf.format(date2));
????Calendar cal1 = Calendar.getInstance();
????Calendar cal2 = Calendar.getInstance();
????cal1.setTime(date1);
????cal2.setTime(date2);
????if(cal1.after(cal2)){
????System.out.println("Date1 is after Date2");
????}
????if(cal1.before(cal2)){
????System.out.println("Date1 is before Date2");
????}
????if(cal1.equals(cal2)){
????System.out.println("Date1 is equal Date2");
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11