Home Java Java-get-example Java get System TimeZone
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java get System TimeZone

Advertisement
In this section, you will learn how to obtain the System's TimeZone. The Time Zone is basically the uniform standard time usually referred to as the local time.

Java get System TimeZone

     

In this section, you will learn how to obtain the System's TimeZone. The Time Zone is basically the uniform standard time usually referred to as the local time. We have used the instance of the class TimeZone in order to get the timeZone by using the method Calendar.getInstance().getTimeZone().

tz.getDisplayName()- This method returns the name of the time zone.

tz.getID()- This method returns the id of the time zone.

Understand with Example

In this example, we want to display the System's Time zone.For this we consider a class GetSystemTimeZone,Inside the main method, we  use the instance of  class Time Zone to obtain the time zone of the specified region by calling  Calendar.getInstance( ).getTimeZone( ) method. The System.out.print ln is used to display the output by calling the following given below method-

1)getDisplayName( )-Provides you the name of time zone.

2)getID( )-  Provides you the id of time zone.

On Execution of the program code, The code returns you Time zone and ID.

 

Here is the code of GetSystemTimeZone.java

import java.util.*;

public class GetSystemTimeZone {
 public static void main(String[] args) {
 TimeZone tz = Calendar.getInstance().getTimeZone();
 System.out.println("TimeZone: "+tz.getDisplayName());
 System.out.println("ID: "+tz.getID());
  }

Output will be displayed as:

Download Source code

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 1, 2008

Ask Questions?    Discuss: Java get System TimeZone  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Jeya kumar.J
February 29, 2012
java

how to get the user inputs
DMCA.com