This seems like it should be easy but my brain is farting, it's Friday, and I've been confused by all the date/time objects Java has... What's the easiest way to create a "time" object, whether Date or GregorianCalendar (whichever is easiest), and set it to 04:00:00 exactly, ie. 4am?
Note that you probably want to call calendar.getTime() afterwards to extract a lightweight Date object representing the time, allowing you to re-use the heavyweight Calendar to create other Dates. And you should be aware that even though it wasn't mentioned, the Calendar (and Date(s)) have year, month, and day information as well - all set to today's date (at time of Calendar creation) unless you change them. This could lead to problems if you are careless - 4 AM using a Calendar created just before midnight is not the same as 4 AM using a Calendar created just after midnight. You may want to manually set the date to some arbitrary constant value whenever you create a Calendar, so this is not an issue.
Originally posted by Jim Yingst: Note that you probably want to call calendar.getTime() afterwards to extract a lightweight Date object representing the time, allowing you to re-use the heavyweight Calendar to create other Dates....
How do you know that Calendar is a heavy weight object and Date is a light weight object? That would be interesting to know about several Classes.
Jim- Thanks for the heads up. To take care of that I get an instance of a calendar, extract the current date from it, set the calendar to 4am, then compare if the current date is before or after 4am on that day and adjust if necessary.
[ October 02, 2002: Message edited by: David Duran ]