Java Convert GMT / UTC na czas lokalny nie działa zgodnie z oczekiwaniami

Aby pokazać powtarzalny scenariusz, robię co następuje

Uzyskaj aktualny czas systemowy (czas lokalny)

Konwertuj czas lokalny na UTC // Działa dobrze Do tutaj

Odwróć czas UTC, z powrotem do czasu lokalnego. Zastosowano 3 różne podejścia (wymienione poniżej), ale wszystkie 3 podejścia zachowują czas tylko w UTC.

{

long ts = System.currentTimeMillis();
Date localTime = new Date(ts);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat (format);

// Convert Local Time to UTC (Works Fine) 
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmtTime = new Date(sdf.format(localTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());

// Reverse Convert UTC Time to Locale time (Doesn't work) Approach 1
sdf.setTimeZone(TimeZone.getDefault());        
localTime = new Date(sdf.format(gmtTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());

// Reverse Convert UTC Time to Locale time (Doesn't work) Approach 2 using DateFormat
DateFormat df = new SimpleDateFormat (format);
df.setTimeZone(TimeZone.getDefault());
localTime = df.parse((df.format(gmtTime)));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());

// Approach 3
Calendar c = new GregorianCalendar(TimeZone.getDefault());
c.setTimeInMillis(gmtTime.getTime());
System.out.println("Local Time " + c.toString());

}

questionAnswers(6)

yourAnswerToTheQuestion