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 of the TimeZone.
Return Value: The method does not return any value.
Below programs illustrate the use of setID() method of TimeZone class:
Example 1:
// Java code to illustrate setID() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getTimeZone( "Pacific/Pago_Pago"); // set time zone ID offtime_zone.setID("GMT+05:00"); // Knowing the DST System.out.println("The ID is: " + offtime_zone.getID()); } } |
The ID is: GMT+05:00
Example 2:
// Java code to illustrate setID() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getDefault(); // set time zone ID offtime_zone.setID("GMT+05:30"); // Knowing the DST System.out.println("The ID is: " + offtime_zone.getID()); } } |
The ID is: GMT+05:30
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#setID(java.lang.String)
Recommended Posts:
- TimeZone clone() Method in Java with Examples
- TimeZone getDefault() Method in Java with Examples
- TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
- TimeZone getAvailableIDs() Method in Java with Examples
- TimeZone getTimeZone() Method in Java with Examples
- TimeZone getDisplayName() Method in Java with Examples
- TimeZone getDSTSavings() Method in Java with Examples
- TimeZone getRawOffset() Method in Java with Examples
- TimeZone getID() Method in Java with Examples
- TimeZone setDefault() Method in Java with Examples
- TimeZone observesDaylightTime() method in Java with Examples
- TimeZone inDaylightTime() method in Java with Examples
- TimeZone getOffset() Method in Java with Examples
- TimeZone hasSameRules() Method in Java with Examples
- TimeZone useDaylightTime() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



