import java.util.Calendar; import java.util.TimeZone; public class TimeZoneExample { public static void main(String[] args) { Calendar calendar = new GregorianCalendar(); TimeZone timeZone = TimeZone.getTimeZone("America/New_York"); calendar.setTimeZone(timeZone); //Printing the Time for New York System.out.println("Time in New York: " + calendar.getTime()); } }
import java.util.Calendar; import java.util.TimeZone; public class TimeZoneExample { public static void main(String[] args) { Calendar calendar = new GregorianCalendar(); TimeZone timeZone = TimeZone.getTimeZone("Asia/Kolkata"); calendar.setTimeZone(timeZone); //Printing the Time for Kolkata System.out.println("Time in Kolkata: " + calendar.getTime()); } }In the above example, the `setTimeZone()` method is used to set the time zone of the calendar object to "Asia/Kolkata". The `getTime()` method returns the time in the specified time zone.