2

My operating system is Windows Server 2012 R2

my server's time zone is UTC +3 İstanbul.

However when I run this code it gives me:

Venezuela Time America/Caracas

The code I run:

System.out.println(TimeZone.getDefault().getDisplayName());
System.out.println(TimeZone.getDefault().getID());

Where does JVM store default timezone information and how can I change it?

note:
the problem is not the code, I'm running Informatica on this server. I just placed the code to be an example. I want to change that info retrieved with TimeZone.getDefault().getDisplayName(). Where and How? My local clock is Turkey

Thanks

Mehmet
  • 1,435
  • 4
  • 13
  • 15
  • Possible duplicate of [Force Java timezone as GMT/UTC](http://stackoverflow.com/questions/2627992/force-java-timezone-as-gmt-utc) – Steven Fougeron May 16 '17 at 12:45

2 Answers2

1

Pass the jvm the variable -Duser.timezone See How to set a JVM TimeZone Properly

Or see Oracle's reference on this topic https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/time-zone002.html

Community
  • 1
  • 1
ipper
  • 624
  • 4
  • 13
0

if you use the TimeZone method, it will retrieve time from your local clock, instead of you could try to use the example below.

Instant now = Instant.now();
System.out.println(now);
ZonedDateTime dateTime = ZonedDateTime.ofInstant(
        now,
        ZoneId.of("Europe/Warsaw")
    );
System.out.println(dateTime);


LocalDate localDate = LocalDate.of(2017, Month.MARCH, 26);
LocalTime localTime = LocalTime.of(1, 0);
ZonedDateTime warsaw = ZonedDateTime.of(localDate, localTime, ZoneId.of("Europe/Warsaw"));
ZonedDateTime oneDayLater = warsaw.plusDays(1);
Duration duration = Duration.between(warsaw, oneDayLater);
System.out.println(duration);



LocalDate localDate = LocalDate.of(2017, Month.APRIL, 2);
LocalTime localTime = LocalTime.of(1, 0);
ZonedDateTime warsaw = ZonedDateTime.of(localDate, localTime, ZoneId.of("Australia/Sydney"));
SharpLu
  • 1,136
  • 2
  • 12
  • 28
  • the problem is not the code, I'm running Informatica on this server. I just placed the code to be example. I want to change that info retrieved with TimeZone.getDefault().getDisplayName(). where and how,? my locl clock is Turkey. – Mehmet May 16 '17 at 12:46
  • Then that are JVM issues, you could add arguments -Duser.timezone="Europe/Turkey" to fix the timezone issue. – SharpLu May 16 '17 at 13:24
  • where should I add that parameter? Thanks by the way – Mehmet May 16 '17 at 14:47