Calendar and Time Zone Support

   

Since version 1.1 of the JDK, the Date class has been used as just a wrapper around a date or time instance. It can represent dates or times with millisecond precision. However, you need more when it comes to working with internationalized dates or times. For this, you need to use the java.util.Calendar class and its subclass java.util.GregorianCalendar. You also can make use of the java.util.TimeZone class to represent time zone offsets and to help in calculating daylight savings. Together, these classes provide a rich library to aid in date and time calculations. The following sections look at each one briefly .

Calendar Class

The java.util.Calendar class is an abstract class that provides culture-independent methods for manipulating the epoch , century, year, month, week, day, and time in various ways. Because the Calendar class is abstract, it relies on the subclasses to provide functionality based on a particular calendar system. The only subclass provided by the Java language itself is the java.util.GregorianCalendar class, which provides sophisticated functionality for the world's most popular calendar system. Future releases might include support for various lunar , seasonal, or other calendar systems. An adjunct to the Calendar class, which is not usually used directly by the programmer, is the TimeZone (and SimpleTimeZone ) class, which allows dates and times to be properly adjusted for other time zones.

The Date, Calendar, and TimeZone classes provide a large amount of functionality that most programmers will never need to know about. You don't need to understand the intricacies of temporal arithmetic to make use of these classes; they all contain default methods that allow you to get the current time and date, and display it in a Locale -sensitive way. By merely using the provided methods, your programs will become localized by default, requiring no added effort on your part.

Note

There are too many methods in these classes to discuss here. If you are interested, a simple example of the Calendar and Date classes interacting is provided in the example at the end of the chapter. For a more complete discussion of the available methods, you should consult the Java API documentation directly.


   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net