Need to get a certain date or time -- other than right now? Here's a hint: don't use java.util.Date. Use java.util.GregorianCalendar instead. For example, if you needed a date object that represented the moment twenty four hours ago:
java.util.GregorianCalendar lastAcceptable =
new java.util.GregorianCalendar();
lastAcceptable.add(java.util.Calendar.HOUR, -24);
You can use any of the constants defined in java.util.Calendar to add or subtract time from a date. Check out the GregorianCalendar API for more information on manipulating and retreiving dates and times.
Comments