I am trying to obtain a simple conversion from one time zone into another using Java Date and Calendar. I am trying to run the following code
Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"));
Date date = instance.getTime();
System.out.println(date);
GregorianCalendar instance2 = new GregorianCalendar(TimeZone.getTimeZone("Europe/Athens"));
instance2.setTime(instance.getTime());
System.out.println(instance2.getTime());
but that still returns the same date, rather than +1 hour… The whole problem seems trivial but i cannot find any simple answer to this. Thanks in advance for your help.
When you print the date using
System.out.println(date); or System.out.println(instance2.getTime());, theDatereturned byinstance2.getTime()isTimeZone independentand always prints the date in local timezone.Instead you may want to use
DateFormat/SimpleDateFormat: