File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "weird java dates!!!!" Watch "weird java dates!!!!" New topic

weird java dates!!!!

Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
hiiii all,
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 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 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, 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

Joined: Oct 27, 2005
Posts: 20273

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.

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:
subject: weird java dates!!!!
jQuery in Action, 3rd edition