Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeZone.getDefault() in linux differs from user to user

I have a linux box with two users configured. I also have this piece of Java code:

long time = System.currentTimeMillis();
String millis = Long.toString(time);
Date date = new Date(time);
System.out.println("Current time in milliseconds = " + millis + " => " + date.toString());
TimeZone tz = TimeZone.getDefault();
System.out.println("Current time zone: " + TimeZone.getDefault().getID());

If I run date on bash I have the same result for both users:

User 1:

$ date
Fri Mar 22 10:02:58 PYST 2013

User 2:

$ date
Fri Mar 22 10:03:22 PYST 2013

However, if I run the same java code I have:

User 1:

$ java TimeTest
Current time in milliseconds = 1363957432669 => Fri Mar 22 10:03:52 PYST 2013
Current time zone: America/Asuncion

User 2:

$ java TimeTest
Current time in milliseconds = 1363957456954 => Fri Mar 22 13:04:16 GMT 2013
Current time zone: GMT

So I guess it has something to do with the way java is configured for each user.

I checked for a TZ environment variable defined, but there is no TZ defined for anyone of the users.

Any ideas on why am I getting different values for TimeZone.getDefault() for different users on the same Linux box?

JVM:

$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

Distro:

$ cat /etc/issue
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
like image 427
Pablo Santa Cruz Avatar asked Nov 13 '22 08:11

Pablo Santa Cruz


1 Answers

It is probably something to do with Locale for the user.

check these variables: http://linux.die.net/man/1/locale

like image 145
Emil Iakoupov Avatar answered Nov 14 '22 22:11

Emil Iakoupov