java 1.4 not setting time zone correctly ...
Jeff Nai
jnai at juniper.net
Mon Sep 29 18:51:19 PDT 2003
On FreeBSD, java 1.4 always defaults time zone to GMT. I'd like to know
if this is a known bug.
% uname -smr
FreeBSD 4.8-RELEASE i386
java -version
java version "1.4.1-p3"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.1-p3-jnai_15_sep_2003_19_22)
Java HotSpot(TM) Client VM (build 1.4.1-p3-jnai_15_sep_2003_19_22, mixed
mode)
% java TimeTest
old: GMT
new: US/Pacific
shell: Mon Sep 29 18:41:24 PDT 2003
normal: Tue Sep 30 01:41:24 GMT 2003
adjusted: Mon Sep 29 18:41:24 GMT 2003
On linxu, time zone is set correctly:
% uname -smr
Linux 2.4.7-10 i686
% java -version
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
% java TimeTest
old: US/Pacific
new: US/Pacific
shell: Mon Sep 29 18:48:47 PDT 2003
normal: Mon Sep 29 18:48:47 PDT 2003
adjusted: Mon Sep 29 11:48:47 PDT 2003
Thanks,
Jeff Nai
-------------- next part --------------
import java.io.InputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;
import java.text.SimpleDateFormat;
public class TimeTest {
public static void main(String[] args) {
final SimpleDateFormat DATE = new SimpleDateFormat("EEE MMM dd kk:mm:ss zzz yyyy");
// change time zone setting
System.out.println("old: " + System.setProperty("user.timezone", "US/Pacific"));
System.out.println("new: " + System.getProperty("user.timezone"));
// output from 'date'
System.out.print("shell: ");
try {
Process child = Runtime.getRuntime().exec("date");
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print((char)c);
}
} catch (IOException e) {}
// output from vm
System.out.println("normal: " + DATE.format(new Date()));
// dirty hack!
Timestamp ts = new Timestamp(System.currentTimeMillis() - 25200000);
System.out.println("adjusted: " + DATE.format(ts));
}
}
More information about the freebsd-java
mailing list