Works fine with OpenJDK6 b19:
hammer# cat TimeTest.java
import java.util.Date;
import java.util.TimeZone;
public class TimeTest {
public static void main(String args[]) {
long time = System.currentTimeMillis();
String millis = Long.toString(time);
Date date = new Date(time);
System.out.println("Current time in milliseconds = " + millis + " => " + date.toString());
System.out.println("Current time zone: " + TimeZone.getDefault().getID());
}
}
hammer# javac -version
javac 1.6.0
hammer# java -version
openjdk version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b19)
OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)
hammer# javac TimeTest.java
hammer# cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime
hammer# date
Wed May 26 03:50:39 KST 2010
hammer# echo $TZ
TZ: Undefined variable.
hammer# java TimeTest
Current time in milliseconds = 1274813492978 => Wed May 26 03:51:32 KST 2010
Current time zone: Asia/Seoul
hammer# cp /usr/share/zoneinfo/America/New_York /etc/localtime
hammer# date
Tue May 25 14:53:10 EDT 2010
hammer# java TimeTest
Current time in milliseconds = 1274813598908 => Tue May 25 14:53:18 EDT 2010
Current time zone: America/New_York
hammer# setenv TZ Asia/Seoul
hammer# echo $TZ
Asia/Seoul
hammer# java TimeTest
Current time in milliseconds = 1274813844489 => Wed May 26 03:57:24 KST 2010
Current time zone: Asia/Seoul
hammer# unsetenv TZ
hammer# echo $TZ
TZ: Undefined variable.
hammer# java TimeTest
Current time in milliseconds = 1274813869066 => Tue May 25 14:57:49 EDT 2010
Current time zone: America/New_York
This code example was taken from:
http://www.minaret.biz/tips/timezone.html
Jung-uk Kim
_______________________________________________
freebs...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "freebsd-java...@freebsd.org"
Kim,
I tried the example from the supplied link. It fails:
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ echo $TZ
bash: TZ ist nicht gesetzt.
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
Do 27 Mai 2010 12:21:59 CEST
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ javac TimeTest.java
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java TimeTest
Current time in milliseconds = 1274955728014 => Thu May 27 10:22:08 GMT 2010
Current time zone: GMT
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ export TZ="Europe/Berlin"
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
Do 27 Mai 2010 12:22:26 CEST
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java TimeTest
Current time in milliseconds = 1274955749029 => Thu May 27 12:22:29 CEST 2010
Current time zone: Europe/Berlin
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ export TZ="Europe/Moscow"
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
Do 27 Mai 2010 14:22:44 MSD
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java TimeTest
Current time in milliseconds = 1274955769236 => Thu May 27 14:22:49 MSD 2010
Current time zone: Europe/Moscow
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ unset TZ
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
Do 27 Mai 2010 12:23:24 CEST
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ echo $TZ
bash: TZ ist nicht gesetzt.
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java TimeTest
Current time in milliseconds = 1274955817132 => Thu May 27 10:23:37 GMT 2010
Current time zone: GMT
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java -version
java version "1.6.0_07"
Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
Diablo Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)
osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$
I am on Diablo.
Is seems like a bug to me actually.
Thanks,
Mike
Works with Diablo as well:
hammer# setenv JAVA_HOME /usr/local/diablo-jdk1.6.0
hammer# java -version
java version "1.6.0_07"
Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
Diablo Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)
hammer# echo $TZ
TZ: Undefined variable.
hammer# javac TimeTest.java
hammer# java TimeTest
hammer# cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hammer# date
Thu May 27 17:26:54 CEST 2010
Current time in milliseconds = 1274974109405 => Thu May 27 17:28:29 CEST 2010
Current time zone: Europe/Berlin
hammer# cp /usr/share/zoneinfo/America/New_York /etc/localtime
hammer# java TimeTest
Current time in milliseconds = 1274974222377 => Thu May 27 11:30:22 EDT 2010
Current time zone: America/New_York
hammer# setenv TZ Europe/Berlin
hammer# java TimeTest
Current time in milliseconds = 1274974302535 => Thu May 27 17:31:42 CEST 2010
Current time zone: Europe/Berlin
hammer# unsetenv TZ
hammer# echo $TZ
TZ: Undefined variable.
hammer# java TimeTest
Current time in milliseconds = 1274974350446 => Thu May 27 11:32:30 EDT 2010
Current time zone: America/New_York
Jung-uk Kim
Sorry, copy-pasto. This line was moved few lines up to here by my
evil mouse. :-(
Jung-uk Kim
If it works with your system then it must be something with ours. I have absolutely no idea what the cause might be. Any pointers?
Thanks,
Mike
Have you updated FreeBSD recently? If so i suggest you reinstall your
timezone configuration, just run tzsetup as root and reselect your timezone.