Set date to the start of a minute
import java.util.Calendar;
import java.util.Date;
public class Main {
public static void main(String[] argv) {
System.out.println(getStartOfMinute(new Date()));
}
public static Date getStartOfMinute(Date day) {
return getStartOfMinute(day, Calendar.getInstance());
}
public static Date getStartOfMinute(Date day, Calendar cal) {
if (day == null)
day = new Date();
cal.setTime(day);
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
return cal.getTime();
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Set:
- Set Date to Noon
- Set Date to the first millisecond of the day, just after midnight.
- Set Date to the first millisecond of the month, just after midnight.
- Set Date to the last millisecond of the day, just before midnight.
- Set Date to the last millisecond of the minute.
- Set Date to the last millisecond of the month, just before midnight.
- Set date to clear the time values
- Set date to the end of the day
- Set Date to the start of the day
- Set date to the end of a day
- Set date to the start of an hour
- Set date to then end of an hour
- Set date to the start of a minute
- Set date to the end of a minute
- Set Calendar to Mid night
- Set year, month and day to a date
- Roll java.util.Date back and forth