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
なんで?理由がわからない!最後の日付は間違っていますが、最後の日付だけです。たとえば、日付を変更すると、出力が再び間違っています。