Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-get-example Get Time Zone

Related Tutorials


 
 

Share on Google+Share on Google+

Get Time Zone

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

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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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 5, 2008

Related Tutorials

Discuss: Get Time Zone  

Post your Comment


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