1 <p>This code converts a 32-bit int value to a 64-bit long value, and then passes that value for a
2 method parameter that requires an absolute time value. An absolute time value is the number of
3 milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
4 For example, the following method, intended to convert seconds since the epoc into a Date, is badly broken:
6 Date getDate(int seconds) { return new Date(seconds * 1000); }
9 <p>The multiplication is done using 32-bit arithmetic, and then converted to a 64-bit value. When a 32-bit
10 value is converted to 64-bits and used to express an absolute time value, only dates in December 1969 and
11 January 1970 can be represented.</p>
12 <p>Correct implementations for the above method are:
14 // Fails for dates after 2037
15 Date getDate(int seconds) { return new Date(seconds * 1000L); }
17 // better, works for all dates
18 Date getDate(long seconds) { return new Date(seconds * 1000); }