Can anyone help with the following problem?
My operating system is the last windows 10 and its time zone (UTC+0300) Istanbul(Daylight saving time was deleted and the time zone was set to +0300after the last rules in Turkey - September 7, 2016)
I am using the latest JDK, which is 1.8.0_131. The Tddata version of this JDK tzdata2017a , which includes time zone changes for Turkey.
This is the tiny part of my application that I implemented in the main method:
import java.util.Date;
import java.util.TimeZone;
public class TestMain {
public static void main(String[] args) {
String timeZoneStr = "Asia/Istanbul";
TimeZone timeZone = TimeZone.getTimeZone(timeZoneStr);
Date localDate = new Date();
System.out.println(localDate);
localDate.setTime(155631515L);
System.out.println(localDate);
System.out.println(getUTCFromLocal(localDate, timeZone));
}
public static Date getUTCFromLocal(Date localDate, TimeZone localTimeZone) {
return new Date(localDate.getTime()-localTimeZone.getOffset(localDate.getTime()));
}
}
Code Result:
Sun May 21 15:19:48 EET 2017
Fri Jan 02 21:13:51 EET 1970
Fri Jan 02 19:13:51 EET 1970
, "Fri Jan 02 18:13:51 EET 1970", "Fri Jan 02 19:13:51 EET 1970".
, (new java.util.Date()), +0300, setTime Date +0200.
new java.util.Date():

localDate.setTime(155631515L) :

JDK.