public static void main(String[] args) throws ParseException {
List<String> strd = new ArrayList<>();
List<Date> date = new ArrayList<>();
strd.add("Sun May 11 03:17:40 UTC 2009");
strd.add("Wed Jun 11 03:17:40 UTC 2008");
strd.add("Mon May 11 03:17:40 UTC 2009");
strd.add("Mon Jun 11 03:17:40 UTC 2009");
strd.add("Sun Jun 11 03:17:40 UTC 2009");
List<Character> letters = new ArrayList<>();
char letter;
for (letter = 'A'; letter <= 'Z'; letter++) {
letters.add(letter);
}
List<String> dateToChar = new ArrayList<>();
for (int j = 0; j < strd.size(); j++) {
try {
String strDate = strd.get(j);
// String strDate = "Mon May 11 03:17:40 UTC 2009";
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
Date dateStr = formatter.parse(strDate);
String formattedDate = formatter.format(dateStr);
System.out.println("Date is ==>" + formattedDate);
Date date1 = formatter.parse(formattedDate);
date.add(date1);
} catch (ParseException e) {
System.err.print(e);
}
}
for (int k = 0; k < date.size(); k++) {
for (int h = 1; h < date.size(); h++) {
if (k != h && k < h) {
if (date.get(k).equals(date.get(h))) {
System.out.println("Equal dates");
} else {
System.out.println("Not Equal dates");
}
}
}
}
}
}
我的问题是,当我进行解析时,输出是:
Date is ==>Mon May 11 03:17:40 UTC 2009
Date is ==>Wed Jun 11 03:17:40 UTC 2008
Date is ==>Mon May 11 03:17:40 UTC 2009
Date is ==>Thu Jun 11 03:17:40 UTC 2009
Date is ==>Thu Jun 11 03:17:40 UTC 2009
Not Equal dates
Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Equal dates
为什么?我无法理解原因!最后的日期是错误的,但只有最后的日期。例如,如果我更改日期,则输出再次错误。