I’d like set a java.util.Date-Objekt to its minimum or maximum time values for a Date (one day).
The way I do it currently (for minimum):
Calendar cal = Calendar.getInstance();
cal.setTime(aDate);
cal.set(Calendar.HOUR, 0);
//... same for minutes, seconds, milliseconds
But this seems a little bit cumbersome. And how do I set the maximum?
Yeah, use JodaTime’s DateMidnight class, as others have suggested.
Or if you can’t switch to JodaTime, use
DateUtils.truncate(Date, field)and theDateUtils.addXyz()methods from Commons Lang: