This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes weird java dates!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "weird java dates!!!!" Watch "weird java dates!!!!" New topic
Author

weird java dates!!!!

Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
hiiii all,
Greetings!
I am facing a really weird problem with java Dates. it goes like this: We need to write a function to which we need to pass a java.util.date and we want to get back the due date, which is the day that is after 3 working days if the input time is before 4 PM, and 4 days if it is after 4 PM.to do this we first created a GregorianCalendar instance and added days to it, one at a time, and checked whether this day is a weekend or not. next we checked with the database to see whether this is a company holiday or not. if it passes these tests, then it is a working day. going by this rule, we found out the resultant date. this seems to be working fine as long as the last day "down the calculation lane" is not a sunday. Its only when its a sunday,that the Gregorian Calendar starts behaving creepy....for example if the starting date is 19th august, then the resultant day is shown to be Monday, August 24th,with some valid time,if we set the timezone properly.now, if you just look into any common Paper (may also be plastic :-) ) calendar you will that 24th is Sunday, not Monday!!! i am attaching the codes below, where th function called is TPlus3.
Please rescue us!!!
Thanks In Advance!!!

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Well apparently, in 3908, August 24th is a Monday

I guess this has something to do with Date.setYear. According to its documentation, this will add 1900 to the year before adding it. It's also quite deprecated; you should use a Calendar to create it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
Hello Rob!
And lots and lots of Thanks! bull's Eye, the problem was with date.setYear(). now we have replaced that with Calendar.set().
Thanks once again for your help, buddy!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: weird java dates!!!!