Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

Using the Calendar Class to Display Current Time in Different Time Zones

import java.util.Calendar; import java.util.TimeZone; public class Main {   public static void main(String[] args) {     Calendar calNewYork = Calendar.getInstance();     calNewYork.setTimeZone(TimeZone.getTimeZone("America/New_York"));     System.out.println("Time in New York: " + calNewYork.get(Calendar.HOUR_OF_DAY) + ":"         + calNewYork.get(Calendar.MINUTE));   } } //Time in New York: 11:51