Chris said:
The code at the link you posted said:
TimeSpan rem = new TimeSpan(
System.currentTimeMillis() - xmas.getTimeInMillis());
System.out.printf("%d days, %d hours and %d minutes till xMas ;-)",
rem.getDays(), rem.getHours(), rem.getMinutes());
It's the days that cause the problem. You can easily get seconds,
minutes, and hours from calculations on the number of milliseconds, but
days depends on the starting time and DST conventions. So no, that code
is not correct.
If I were implementing this stuff:
a) I'd use a number of milliseconds as the internal representation of a
time interval or duration.
b) Date objects would internally wrap milliseconds since the epoch, in a
long, and be UTC. To get a localized date it would be interpreted
relative to a Locale to get its date and time in a particular time zone.
Localization of dates would be a peripheral thing; the core data would
all be in UTC, and you could compare and find that the current date in
london and the same date in new york were equal even though they printed
differently, etc. There'd be separate Date (UTC) and LocalizedDate classes.
c) Failing b), I'd have all calculations internally change incoming
dates to UTC and results to the desired locale. Date parameters would be
accompanyable by optional Locale objects and without them interpreted
relative to the system locale.