Java Reference
In-Depth Information
The Date class implements the Comparable<Date> interface so you have the compareTo() method
available. As you've seen in other contexts, this method returns a negative integer, zero, or a positive integer
depending on whether the current object is less than, equal to, or greater than the argument. The presence
of this method in the class means that you can use the sort() method in the Arrays class to sort an array
of Date objects, or the sort() method in the Collections class to sort a collection of dates. Because the
hashCode() method is also implemented for the class, you have all you need to use Date objects as keys in
a hash map.
Interpreting Date Objects
The DateFormat class is an abstract class that you can use to create meaningful String representations
of Date objects. It isn't in the java.util package though — it's defined in the package java.text . You
have four standard representations for the date and the time that are identified by constants defined in the
DateFormat class. The effects of these vary in different countries, because the representation for the date
and the time reflects the conventions of those countries. The constants in the DateFormat class defining the
four formats are shown in Table 15-1 .
TABLE 15-1 : Date Formats
DATE
FORMAT
DESCRIPTION
A completely numeric representation for a date or a time, such as 2/2/97 or 4:15 a.m.
SHORT
A longer representation than SHORT , such as 5-Dec-97
MEDIUM
A longer representation than MEDIUM , such as December 5, 1997
LONG
A comprehensive representation of the date or the time such as Friday, December 5, 1997 AD or 4:45:52
PST (Pacific Standard Time)
FULL
A java.util.Locale object identifies information that is specific to a country, a region, or a language.
You can define a Locale object for a specific country, for a specific language, for a country and a language,
or for a country and a language and a variant, the latter being a vendor- or browser-specific code such as WIN
or MAC . When you are creating a Locale object, you use ISO codes to specify the language or the country
(or both). The language codes are defined by ISO-639. Countries are specified by the country codes in the
standard ISO-3166. You can find the country codes on the Internet at www.iso.org/iso/country_codes .
You can also get a list of the country codes as an array of String objects by calling the static
getISOCountries() method. For example:
String[] countryCodes = java.util.Locale.getISOCountries();
You can find the language codes at www.loc.gov/standards/iso639-2/php/English_list.php .
You can also get the language codes that are defined by the standard in a String object:
String[] languages = java.util.Locale.getISOLanguages();
For some countries, the easiest way to specify the locale, if you don't have the ISO codes on the tip of
your tongue, is to use one of the static Locale objects defined within the Locale class:
 
 
Search WWH ::




Custom Search