私は2つの日付を検証する必要があります。1つはユーザーが選択し、もう1つはカレンダーから取得したものです...これは私がこれまで成功せずに試したことです:
Calendar c = Calendar.getInstance();
if(!DateIsOlder(txtVwAppointmentDate.getText(), c.getTime())) {
try {
//My code
}
public static boolean DateIsOlder(CharSequence date1, Date date2){
//SimpleDateFormat Date2 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz -HH:mm yyyy", Locale.ENGLISH);
SimpleDateFormat dfDate = new SimpleDateFormat("dd/mm/yyyy", Locale.ENGLISH);
boolean isOlder = false;
try{
//Date newDate = (Date)Date2.parse(date2);
if(dfDate.parse(String.valueOf(date1)).before(dfDate.format(date2))){
isOlder = true;
}
else if (dfDate.parse(String.valueOf(date1)).equals(dfDate.format(date2))){
isOlder = false;
}
else {
isOlder = false;
}
}catch (Exception e){
e.printStackTrace();
}
return isOlder;
}
エラーは .before(dfDate.format(date2)) にあり、次のように表示されます: Error:(484, 51) error: method before in class Date cannot be applied to given types; 必須: 見つかった日付: 文字列 理由: 実引数文字列はメソッド呼び出しの変換で日付に変換できません
ご覧のとおり、両方の日付が等しい場合に両方の日付を比較すると、コンパイラはこの行にエラーを表示しません。
else if (dfDate.parse(String.valueOf(date1)).equals(dfDate.format(date2)))
また、日付に変更しようとしましたが、成功しません...この問題を解決するのに役立つアイデアはありますか? ありがとう。