[ Back | Previous | Next ]

How to round of a Calendar to a Calendar unit?

Package:
java.util.*
Product:
JDK
Release:
1.1.x
Related Links:
Calendar
EventObject
Hashtable
Locale
Properties
PropertyResourceBundle
TimeZone
Comment:
In time travel applications its sometimes necessary to round of calendars. For instance if
you want to increase the minutes on an interval or deltaT of 10 minutes.
This method will do this for U?

 

/** * Increasing the minutes on an interval or deltaT of 10 minutes. * @param unit int (Calendar.MINUTE, Calendar.HOUR…) * @param cal java.util.GregorianCalendar * @param dT int */ private static void roundCalendar(int unit, GregorianCalendar cal, int dT) { int min = cal.get(unit); min = min - (min % dT); // nieuwe calender met afgeronde minuten en // geresette milliseconden en seconden. //dd.add(Calendar.HOUR, -1); // timezone!!! cal.set(unit, min); }
1