Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JRE uses wrong timezone

899679Jun 26 2015 — edited Jul 1 2015

Hello,

I have a problem with timezone in my java application.

My current/correct timezone is "Europe/Berlin" or CEST.

When I type the following command as my user I get the correct output back:

$ date "+%Z %z"

CEST +0200

But when I run my java application it is using the timezone GMT+0100. I have executed the following Java code to verify:

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());

        System.out.println("useDaylightTime = " + tz.useDaylightTime());

        System.out.println(date);

    }

}

When I run it the following output is generated:

Current time in milliseconds = 1435319087443 => Fri Jun 26 12:44:47 GMT+01:00 2015

Current time zone: GMT+01:00

Fri Jun 26 12:44:47 GMT+01:00 2015

So where does java get its timezone from? It's different from the default system timezone.

Im running on Redhat 6.6 with Java 1.7.0_79

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

This post has been answered by 899679 on Jul 1 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2015
Added on Jun 26 2015
2 comments
648 views