Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Getting Information of All Available Time Zones 
 

In this section, the given program shows you how to get about all the information for the time zones.

 

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.

                         

» View all related tutorials
Related Tags: c string reference io method type boolean key rmi ole this ai node oo create if boo example to contains

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

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.

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

Current Comments

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

Hi, there!
can you help me?
I want to understand how to calculate time between two cities in java or c#
thanks!

Posted by makiese on Thursday, 10.30.08 @ 10:12am | #81406

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.