Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Getting Information of All Available Time Zones

                         

Time Zone: Time Zone is the specified part of the earth that holds the special standard of the time i.e. termed as local time. Usually time zone is based on the GMT (Greenwich Mean Time). Each and every part of the earth has categorized for holding it's own time zones that had been fixed according to the rotation of the earth on it's own base.

Most application software uses the underlying operating system for getting all information about the time zones for setting up the time according to the appropriate time zones. Java maintains it's own time zones database as well as the operating system database. There need to update the java time zone database from the operating system database when it is changed.

DST (Daylight Saving Time): Daylight Saving Time is also called the summer time somewhere in many countries. In this period the sun rises in the morning and sets in the evening one hour later. So, the evening became one hour longer. Benefit of the period is saving energy because in this period artificial light is less needed during the evening. To make DST work, when DST begins, clocks have to be adjusted one hour ahead and adjusted one hour back to standard time every autumn. Many countries maintain the DST and many do not.

Up to now, most of the United States have observed Daylight Saving Time from the first Sunday of April at 2:00 am to the last Sunday of October at 2:00 am. In 2007, most of the U.S. will begin Daylight Saving Time from the second Sunday of March at at 2:00 a.m. and revert to standard time on the first Sunday in November. In the U.S., each time zone switches at a different time.

Program Result:

In this section, the given program shows you how to get about all the information for the time zones. This program shows all time zones available in the world with the Time Zone ID, Time Zone Name and it's fixed GMT (India Standard Time : 5:30).

Code Description:

TimeZone:
This class is used to getting and setting the time zone. You can get the default time zone using the getDefault() method i.e. the time zone on where your program is running.

TimeZone.getAvailableIDs():
Above method returns a array of all time zone ids like the time zone id for the time zone of India is Asia/Calcutta.

TimeZone.getTimeZone(id):
Above method returns the full name of the Time Zone. The time zone id, which full name has to be found, is passed through the method as a parameter.

TimeZone.getDisplayName(TimeZone.inDaylightTime(new Date()), TimeZone.LONG):
Above code of the program represents two methods and a field of the TimeZone class these are explained as follows:

  • TimeZone.LONG:
    This field of the TimeZone class returns a static integer value which is used in the getDisplayName() method of the class as a parameter for specifying the style of the name of the time zone. It determines the long (full) name of the specific time zone. Another field is the TimeZone.SHORT which determines the short name of the time zone.
      
  • TimeZone.inDaylightTime(new Date()):
    This method returns the abstract boolean type value after checking whether the given date is in the Daylight Saving Time period or not. It returns true, if the date is in the DST (Daylight Saving Time) otherwise false.
      
  • TimeZone.getDisplayName(TimeZone.inDaylightTime(new Date()), TimeZone.LONG):
    This method gives you the full name of the specified time zone. This method returns String type value which is the name of the time zone for the specified Locale.

TimeZone.getRawOffset():
Above method returns the amount of time to add UTC () to get standard time for the specified time zone. This method returns the static integer value which is the amount of time in millisecond.

Math.abs(real_number):
This method returns the absolute number for the given number. The number, which has to become absolute, is passed through the method as a parameter.

Here is the code of the program:

import java.util.*;

public class TimeZones{
  public static void main(String[] args){
    Date date = new Date();
    String TimeZoneIds[] = TimeZone.getAvailableIDs();
    for(int i = 0; i < TimeZoneIds.length; i++){
      TimeZone tz = TimeZone.getTimeZone(TimeZoneIds[i]);
      String tzName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.LONG);
      System.out.print(TimeZoneIds[i":   ");
      // Get the number of hours from GMT
      int rawOffset = tz.getRawOffset();
      int hour = rawOffset / (60*60*1000);
      int minute = Math.abs(rawOffset / (60*1000)) 60;
      System.out.println(tzName + " " + hour + ":" + minute);
    }
  }
}

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.