This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I shouldn't be hesitating to tell you that I am getting stuck in setting up this time using date object.
I create date object Date dt = new Date();
This will return me current date & time then I need to set this timing for every day 6.40 am.but don't know how to do it.
I tried dt.setHours() which is depricated & also dt.setTime(in miliseonds); but not getting the correct way to do it.
Can you please tell me How to create a Date object that points to 6.30 AM tomorrow and 24hrs period. I would apriciate that.
Thanks again !!
Joined: Mar 22, 2005
Something like this should do the trick. Don't be put off by the fact that most methods of the Date class are deprecated - they work fine. Just be aware that Date has no concept of timezones (which is just fine in this case).
Indeed, the methods in class Date are deprecated, and that means you should not use them, even though they do work. To do this the "right" way, use a Calendar object to set the date and time, and then call getTime() on the Calendar object to get the Date object:
Hate to point out a minor bug. But the original request was for 6:30am everyday (not starting the next day). Hence, you should set the time to 6:30am first, and then set the day to the next day, only if the time has past for the current day.