Get Time Zone

Time Zone class inherits from a Java.util.time zone. This class represents a time zone offset.


 
Ads

Get Time Zone

     

Time Zone class inherits from a Java.util.time zone. This class represents a time zone offset. The Time zone gives you a specific time zone of a specific locale where the program is running. In case a program running in USA,This class creates a time zone object based on USA.

Understand with Example

In this Tutorial we want to describe you a code that help you in understanding a Get Time Zone. For this we have a Class name Get Time Zone. Inside the main method  the calendar class call a get Instance  ( ) method returns you the default zone and locale and  in order to get an instance of calendar class in a  calendar object. The calendar object calls  getTimeZone method  and return the calendar current's time of the zone by System.out.println. method.  Time Zone ( ) is a static  method that return you all the Id supported. Date Format is a abstract class used for date, time  formatting class.

Date Format df   = DateFormat.getDateInstance( )  - The DateFormat.getDateInstance returns you the date for the different  locale. This provides you to get the time format for a specified country.

The System.out.println print the time zone  for a given id .

GetTimeZone.java

import java.util.*;
import java.text.*;

public class GetTimeZone {

  public static void main(String args[]) {

  Calendar calendar = Calendar.getInstance();
  TimeZone timeZone = calendar.getTimeZone();

  System.out.println("Time Zone :" + timeZone.getID());

  DateFormat df = DateFormat.getDateInstance();
  System.out.println("Time Zone :" + df.getTimeZone().getID());
  }
}

Output
Time Zone :GMT+05:30
Time Zone :GMT+05:30
Download code

Advertisements

Share on Google+Share on Google+

Get Time Zone

Posted on: November 5, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Get Time Zone  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads