Calendar getTimeZone() Method in Java with Examples
The getTimeZone() method in Calendar class is used to return the current time-zone of this Calendar.
Syntax:
public TimeZone getTimeZone()
Parameters: The method does not take any parameters.
Return Value: The method returns timezone of this Calendar object.
Below programs illustrate the working of getTimeZone() Method of Calendar class:
Example 1:
Java
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr = Calendar.getInstance();
TimeZone time_zone = calndr.getTimeZone();
System.out.println( "The current Time zone is: "
+ time_zone.getDisplayName());
}
}
|
Output:
The current Time zone is: Coordinated Universal Time
Example 2:
Java
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr = Calendar.getInstance();
TimeZone time_zone = calndr.getTimeZone();
System.out.println( "The current Time zone is: "
+ time_zone.getDisplayName());
calndr.setTimeZone(
TimeZone.getTimeZone( "GMT" ));
System.out.println( "New TimeZone: "
+ calndr.getTimeZone()
.getDisplayName());
}
}
|
Output:
The current Time zone is: Coordinated Universal Time
New TimeZone: Greenwich Mean Time
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getTimeZone–
Last Updated :
29 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...