Convert time between timezone : TimeZone « Development Class « Java

Convert time between timezone


import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
  public static void main(String[] args) {
    Calendar localTime = Calendar.getInstance();
    localTime.set(Calendar.HOUR, 17);
    localTime.set(Calendar.MINUTE, 15);
    localTime.set(Calendar.SECOND, 20);

    int hour = localTime.get(Calendar.HOUR);
    int minute = localTime.get(Calendar.MINUTE);
    int second = localTime.get(Calendar.SECOND);

    System.out.printf("Local time  : %02d:%02d:%02d\n", hour, minute, second);

    Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany"));
    hour = germanyTime.get(Calendar.HOUR);
    minute = germanyTime.get(Calendar.MINUTE);
    second = germanyTime.get(Calendar.SECOND);

    System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second);


Related examples in the same category

1.Format TimeZone in z (General time zone) format like EST.
2.Format TimeZone in zzzz format Eastern Standard Time.
3.Format TimeZone in Z (RFC 822) format like -8000.
4.Display Available Time Zones
5.Get all available timezones
9.Converting Times Between Time Zones
10.Getting the Current Time in Another Time Zone
11.Using the Calendar Class to Display Current Time in Different Time Zones
12.Get current TimeZone using Java Calendar
13.Create a Calendar object with the local time zone and set the UTC from japanCal
14.Get the time in the local time zone
15.Timezone conversion routines
16.Convert the date to the given timezone