They differ by about 1 hour (60 * 60 * 1000) as if
system clock was wrong but it isn't.
That sounds suspiciously like a daylight saving problem.
Did someone manually adjust the clock by one hour rather than setting
the timezone and letting the OS adjust?
In all your calculations, keep printing the timezone to make sure it
is what you think, also the various offsets.
Seehttp://mindprod.com/jgloss/timezone.html
As I said both system clock and TZ appear to be correct .
That's what this code fragment produces:
TimeZone tz1 = TimeZone.getDefault();
System.out.println(tz1.getDisplayName());
System.out.println(System.getProperty( "user.timezone" ));
System.out.println(new Date());
Central European Time
Europe/Rome
Fri Jan 04 09:22:36 CET 2008
While the OS date command produces:
Fri Jan 4 08:22:48 Europe/Rome 2008
N.B. the env command shows:
Hmm, you shouldn't need to have TZ set. Maybe there is a fault in the system
clock and you have modified your shell environment to counter this. What
version of RedHat are you running? The timezone should be set
by /etc/localtime. The Linux system clock works in UTC, or more correctly the
number of seconds since 00:00 Jan 1 1970 UTC. When you ask for a date/time this
is converted into a local wall clock time based on your timezone setting.
The hardware clock must be set to either UTC or local wall clock time, and the
system configured accordingly. This allows the system clock to be set correctly
when the system boots, which is the only time that Linux normally consults the
hardware clock. Using wall clock time for the hardware clock means you are
responsible for manually altering the hardware clock for DST otherwise the
system clock will be wrong after a re-boot, hence you normally set it to UTC.
You would normally only use wall clock time if the system is dual-boot with
Windows because Windows works in local time (and adjusts the hardware clock for
DST). Linux does its best to correct the broken way that Windows does things,
but it's not infallible.
The system may be converting the "seconds since the epoch" to local time
differently from that of your shell. However I'd expect that Java would use the
same environment as your shell, always supposing you are running Java from the
same shell. What does the command 'date "+%s"' output? This is what the system
clock (not the hardware clock) thinks is the number of seconds since the start
of 1970 (in UTC). It is also what Java System.currentTimeMillis() should
output (times 1000). If this is wrong it most likely means the hardware (and
therefore system) clock is incorrectly set.
Is your hardware clock set to UTC or CET? Is the system setup accordingly so the
system clock is correctly set from the hardware clock? What's
in /etc/sysconfig/clock?
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : (e-mail address removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555