私はDate field
を入力パラメータとする方法があります。私が何をしたか日付ゼロの検証Javaで
public static String formatDate(Date inputDate) {
// if user send the date with inputDate= new Date(00000000) or new Date(0L) because it is Java default date.
I have to send the exception error with message Invalid date.
}
として以下のものです、しかし、私はinputDateパラメータとしてゼロカウントからエポック「新日(0L)」のようなの無効な日付を通過する間にエラーを取得することができません。
public static String formatDate(Date inputDate) {
if (null == inputDate)
throw new FieldFormatException("Empty date field.");
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
return formatter.format(inputDate);
} catch (Exception ex) {
throw new FieldFormatException("Exception in formatting date field." + ex);
}
}
「inputDate = 00000000で日付を送信した場合」は意味がありません。「inputDate」は「String」ではなく「Date」です。 –
私が意味するのは '新しい日付(0L)'または8つの長さ0の値です。 '19700101'に変換するのではなく、無効な日付です。 –
そうです、それは*非常に、非常に*不明でした。単に 'Date.getTime()'を呼び出して、それが0を返すかどうかを確認するのはなぜですか? –