1 2 3 4 5 6 7 8 9 10 11 12 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/New_York")); DateFormat df = new SimpleDateFormat("EEE yyyy-MM-dd HH:mm:ss"); df.setTimeZone(cal.getTimeZone()); System.out.println("The date and time in the specific timezone: " + cal.getTimeZone().getID()); System.out.println(df.format(cal.getTime())); System.out.println("\nThe date and time in the system time zone: " + Calendar.getInstance().getTimeZone().getID()); df.setTimeZone(Calendar.getInstance().getTimeZone()); System.out.println(df.format(Calendar.getInstance().getTime())); |
Output:
1 2 3 4 5 6 7 |
The date and time in the specific timezone: America/New_York Fri 2016-04-29 17:34:15 The date and time in the system time zone: America/Los_Angeles Fri 2016-04-29 14:34:15 |