Hi, I barely know what I am doing but ... I was playing with the Calendar class, trying to get the difference in milliseconds, then days, between two dates.
All was going well until I noticed, don't ask me how, that 3 Oct 2010 seems to only have 23 hours (0.958333 days).
I wrote, probably badly, a little console program to take in two dates and get the number of days between them. If you enter (dd/mm/yyyy) 3/10/2010 as the start date, and 4/10/2010 as the end date, the program gives a difference of 0.958333 days. All other days give a difference of 1.00000 days.
Calendar also has a funny "feature" (?) when changing from winter to summer time: if you have a Date set to 2am the day before summer time change, and then add() one day, the hour field gets set to 1am. So, for example "2010-03-27 02:00" becomes "2010-03-28 01:00". It only happens when the hour field has the value 2, for all other values it works correctly (?). Cost me some hours of debugging once.
posted 8 years ago
Doh! Yes, I'm in the south of Australia, so it will be the start of daylight saving time.
Thanks very much for your help. No doubt I'll be back with more uneducated observations.
I'm doing an introductory Javaunit at uni, but thought that setting myself an extra-curricula project might be fun. So I'm trying to write a little program in which I can read my relatives' birthdates from a file, compare with the current date, and output something like "Uncle Fred's birthday in 23 days. He will be 102!", which will, hopefully, help me remember his birthday and become a beneficiary in his will.
So, I'm just after whole days difference.
I noticed, by being somewhat obsessive, that my little program was accurate up until 3 Oct, then seemed to be a day short. (As chronicled above.)
My first thought is to end the above program by adding a couple of hours to the daysDiff calculation and casting to an int: