Reputation: 1535
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
Upvotes: 2
Views: 653
Reputation: 784
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
Upvotes: 1
Reputation: 1214
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"));
Upvotes: 0