Rudimentary problem(?) with built-in class...
Hi, I have been playing with the Date class of the java.util package and hit a very fundamental brick wall.
The class, as you know, records the time in milliseconds from the "epoch" (January 1st, 1970). The current time therefore is approx 1*10**12.
Because I am new to the Java world I thought I must just try something simple and set myself the problem of finding out what the date was at exactly a thousand billion milli-seconds from the epoch... but I can't.
java.util.Date.setDate takes a long integer variable. On my system, and Intel Mac, the java long is a signed 32bit number. It means if I try to set the current day to anything greater than 2147483647 ticks the compler throws a number too large error. This is a problem, because 2147483647 milliseconds after Jan 1st 1970 doesn't even get you to the end of the month! With a signed 32bit long you can set no date later than 25th January 1970.
So where's the bug? You could ask, why use Date when I could be using GregorianCalendar? And the answer is simply that the date methods I'm using are not deprecated.
I don't know if my long ints would be longer than 32 if I was using a different platform. I don't know if I can set the length in my compiler. All the literature I have seen tells me a Java long is 64bits but on this Intel Mac it isn't. Here is a simple source code example:
import java.util.Date;
publicclass date{
publicstaticvoid main(String[] args)
{
// Construct new Date object.
Date date =new Date();
// Display current date to console in both milli-ticks and standard format.
System.out.println(date.getTime());
System.out.println(date);
// Make a variable for time scalar.
long time;
// Try setting date to smallest long int and display.
time = -2147483648;
date.setTime(time);
System.out.println(date);
// Try setting date to largest long int and display.
time = 2147483647;
date.setTime(time);
System.out.println(date);
}
}
Obviously a date that can only be set to between 7th December 1969 and Jan 25th 1970 isn't much use. So have I made a mistake or should the entire Date class be deprecated?
What confuses me is that if I let the system just give me the current date, it's fine.
PS. Any tips of my coding style would be greatly appreciated. I've tried writing bigger programs and things get messy!

