Getting the Current Time in Another Time Zone : TimeZone « Development Class « Java

Getting the Current Time in Another Time Zone


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

public class Main {
  public static void main(String[] argv) throws Exception {

    // Get the current time in Hong Kong
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong"));

    int hour12 = cal.get(Calendar.HOUR); // 0..11
    int minutes = cal.get(Calendar.MINUTE); // 0..59
    int seconds = cal.get(Calendar.SECOND); // 0..59
    boolean am = cal.get(Calendar.AM_PM) == Calendar.AM;

    // Get the current hour-of-day at GMT
    int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23

    // Get the current local hour-of-day
    hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23


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
6.Convert time between timezone
10.Converting Times Between Time Zones
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