This discussion is archived
4 Replies Latest reply: Jan 18, 2013 3:06 PM by EJP RSS

Problem occured when Windows 7 TimeZone is set to Istanbul

985753 Newbie
Currently Being Moderated
Hi all;

In our company we have a problem. When we set Windows TimeZone information to *"(UTC+02:00) Istanbul"* Java Date and Calendar objects returned wrong time value. Whenever we change the TimeZone to *"(UTC+02:00) Athens, Bucharest"* the problem solved and Date and Calendar objects returned correct information. And during all of this change operation Windows System time showed always correct value.

In our test we difference between two TimeZone is 07:30 hours. For example when we select Athens as a Timezone then time is 15:05, at the same time we change to TimeZone to Istanbul same code sowed 08:35.

In our code we solve this problem by changing TimeZone information to Athens. But what is the main reason for this problem. Why the java made this calculation. Why not only showed the system time.

We use Java 1.6.

And Here is the sample code
---------
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

class mySample {

private static SimpleDateFormat format=new SimpleDateFormat("HHmm");
private static Locale myLocale=new Locale("tr","TR");

public static void main(String args[]) {
String hourmin=null;
Date date=new Date();
System.out.println("Time zone is seto to Istanbul");
System.out.println("");

hourmin = new SimpleDateFormat("HHmm").format(date);
System.out.println("Getting system time.....:"+hourmin);
System.out.println("Calendar time...........:"+format.format(Calendar.getInstance().getTime()));
System.out.println("Calendar timeL..........:"+format.format(Calendar.getInstance(myLocale).getTime()));

TimeZone.setDefault(TimeZone.getTimeZone("Europe/Athens"));
hourmin = new SimpleDateFormat("HHmm").format(date);
System.out.println("Getting system time.....:"+hourmin+"-> This is the correct value");
System.out.println("Calendar time...........:"+format.format(Calendar.getInstance().getTime()));
System.out.println("Calendar timeL..........:"+format.format(Calendar.getInstance(myLocale).getTime()));

}
}
-----------

Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points