DateFormat setTimeZone() Method in Java with Examples Last Updated : 01 Apr, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The setTimeZone() method in DateFormat class is used to set the time-zone of the calendar of this DateFormat. Syntax: public void setTimeZone(TimeZone time_zone) Parameters: The method takes one parameter time_zone of TimeZone type and refers to the new time zone. Return Value: The method does not return any value. Below programs illustrate the working of setTimeZone() Method of DateFormat class: Example 1: Java // Java code to illustrate // getTimeZone() method import java.text.*; import java.util.*; public class DateFormat_Demo { public static void main(String[] argv) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateInstance(); // Converting the dateformat to string String str = DFormat.format(new Date()); // Original TimeZone System.out.println( "The original timezone is: " + DFormat.getTimeZone() .getDisplayName()); TimeZone time_zone = TimeZone.getTimeZone("GMT"); // Modifying the time zone DFormat.setTimeZone(time_zone); // Getting the modified timezones System.out.println( "New TimeZone is: " + DFormat.getTimeZone() .getDisplayName()); } } Output: The original timezone is: Coordinated Universal Time New TimeZone is: Greenwich Mean Time Example 2: Java // Java code to illustrate // getTimeZone() method import java.text.*; import java.util.*; public class DateFormat_Demo { public static void main(String[] argv) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateInstance(); // Converting the dateformat to string String str = DFormat.format(new Date()); // Original TimeZone System.out.println( "The original timezone is: " + DFormat.getTimeZone() .getDisplayName()); TimeZone time_zone = TimeZone.getTimeZone("Pacific/Tahiti"); // Modifying the time zone DFormat.setTimeZone(time_zone); // Getting the modified timezones System.out.println( "New TimeZone is: " + DFormat.getTimeZone() .getDisplayName()); } } Output: The original timezone is: Coordinated Universal Time New TimeZone is: Tahiti Time Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#setTimeZone(java.util.TimeZone) Comment More infoAdvertise with us Next Article TimeZone setDefault() Method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Functions Java-text package Java-DateFormat +1 More Practice Tags : JavaMisc Similar Reads Calendar setTimeZone() Method in Java with Examples The setTimeZone(TimeZone time_zone) method in Calendar class takes a Time Zone value as a parameter and modifies or set the timezone represented by this Calendar. Syntax: public void setTimeZone(TimeZone time_zone) Parameters: The method takes one parameter time_zone of Date type and refers to the g 2 min read DateFormat setCalendar() Method in Java with Examples The setCalendar() Method of DateFormat class in Java is used to set the calendar associated with this date/time format object. In the initial stage the default settings of calendar is used along with the default locale. Syntax: public void setCalendar(Calendar new_calendar) Parameter: The method tak 2 min read TimeZone setID() Method in Java with Examples The setID(String ID) method of TimeZone class in Java is used to set the time zone ID of this TimeZone. While this operation no other data of the time zone object is changed. Syntax: public void setID(String ID) Parameters: The method takes one parameter ID of String type which refers to the new ID 1 min read TimeZone setID() Method in Java with Examples The setID(String ID) method of TimeZone class in Java is used to set the time zone ID of this TimeZone. While this operation no other data of the time zone object is changed. Syntax: public void setID(String ID) Parameters: The method takes one parameter ID of String type which refers to the new ID 1 min read TimeZone setDefault() Method in Java with Examples The setDefault(TimeZone zone) method of TimeZone class in Java is used to set the TimeZone of the object that is returned by the getDefault() method of the TimeZone class. Syntax: public static void setDefault(TimeZone zone) Parameters: The method takes one parameter zone of TimeZone type which refe 1 min read TimeZone setDefault() Method in Java with Examples The setDefault(TimeZone zone) method of TimeZone class in Java is used to set the TimeZone of the object that is returned by the getDefault() method of the TimeZone class. Syntax: public static void setDefault(TimeZone zone) Parameters: The method takes one parameter zone of TimeZone type which refe 1 min read Like