Online Java Compiler By
JavaTpoint.com
import java.util.Calendar; import java.util.TimeZone; public class JavaCalendarsetTimeZoneExample1 { public static void main(String[] args) { Calendar mycal = Calendar.getInstance(); //getting the display name of TimeZone therwise it will return in object form System.out.println(" TimeZone:" + mycal.getTimeZone().getDisplayName()); // set the time zone of mycal to GMT mycal.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println("Time Zone after changing to GMT:" + mycal.getTimeZone().getDisplayName()); } }
Output