From owner-freebsd-java@FreeBSD.ORG Tue May 25 19:02:06 2010 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from [127.0.0.1] (unknown [IPv6:2001:4f8:fff6::28]) by hub.freebsd.org (Postfix) with ESMTP id 23E0F1065676; Tue, 25 May 2010 19:02:04 +0000 (UTC) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim To: freebsd-java@freebsd.org Date: Tue, 25 May 2010 15:01:52 -0400 User-Agent: KMail/1.6.2 References: In-Reply-To: MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201005251501.55560.jkim@FreeBSD.org> Cc: "Osipov, Michael" Subject: Re: Timezone behavior of Java X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 May 2010 19:02:06 -0000 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