2 つの日付を比較したいという問題に遭遇しました。ただし、年、月、日のみを比較したかっただけです。そして、これは私が思いつくことができるものです:
private Date trim(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR, 0);
return calendar.getTime();
}
この機能を使用して、日、月、年以外のすべての単位をトリムします。
さて、問題はそれについてどう思いますか?そうする他の方法を知っていますか?
ありがとう