Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Timezone behavior of Java

3 views
Skip to first unread message

Jung-uk Kim

unread,
May 25, 2010, 3:01:52 PM5/25/10
to
On Tuesday 25 May 2010 05:14 am, Osipov, Michael wrote:
> Hi folks,
>
> I came recently across a problem with the timezone settings in our
> Jetty on our machine.
>
> This is the ouput:
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ echo $LANG
> de_DE.UTF-8
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
> Di 25 Mai 2010 11:10:46 CEST
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ echo $TZ
> bash: TZ ist nicht gesetzt.
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ javac
> ShowTimezone.java
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java
> ShowTimezone
> sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylig
>ht=false,transitions=0,lastRule=null]
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ export
> TZ="Europe/Berlin"
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ date
> Di 25 Mai 2010 11:11:25 CEST
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$ java
> ShowTimezone
> sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSav
>ings=3600000,useDaylight=true,transitions=143,lastRule=java.util.Sim
>pleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDa
>ylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDa
>yOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,end
>Day=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
> osipovmi@blnn719x:/.amd_mnt/blnn728x/home/osipovmi$
>
> Java source: System.out.println(TimeZone.getDefault());
>
> How can this be explained? Do I have to set the TZ variable
> globally? I assumed from date's behavior that /etc/localtime will
> suffice.

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"

Osipov, Michael

unread,
May 27, 2010, 7:40:56 AM5/27/10
to
Jung-uk Kim wrote:
> On Tuesday 25 May 2010 05:14 am, Osipov, Michael wrote:
>> Hi folks,
>>[...]

>
> Works fine with OpenJDK6 b19:
>
> [...]

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

Jung-uk Kim

unread,
May 27, 2010, 11:34:06 AM5/27/10
to
On Thursday 27 May 2010 07:40 am, Osipov, Michael wrote:
> Jung-uk Kim wrote:
> > On Tuesday 25 May 2010 05:14 am, Osipov, Michael wrote:
> >> Hi folks,
> >>[...]
> >
> > Works fine with OpenJDK6 b19:
> >
> > [...]
>
> Kim,
>
> I tried the example from the supplied link. It fails:
--- >8 --- SNIP!!! --- >8 ---

> 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.

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

Jung-uk Kim

unread,
May 27, 2010, 11:38:06 AM5/27/10
to

Sorry, copy-pasto. This line was moved few lines up to here by my
evil mouse. :-(

Jung-uk Kim

Osipov, Michael

unread,
Jun 1, 2010, 8:36:25 AM6/1/10
to
> 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,

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

Mike Jakubik

unread,
Jun 1, 2010, 4:03:03 PM6/1/10
to

On 6/1/2010 8:36 AM, Osipov, Michael wrote:
> 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?
>
>

Have you updated FreeBSD recently? If so i suggest you reinstall your
timezone configuration, just run tzsetup as root and reselect your timezone.

0 new messages