Canada, and Australian dollars in Australiato name but a few. The local
currency symbol is usually reserved for the local currency, so each locale can
change the representation used for other currencies. For example, if this
currency object represents the U.S. dollar, then invoking getSymbol with a
U.S locale will return "$" because it is the local currency. However,
invoking getSymbol with a Canadian locale will return "USD" (the
currency code for the U.S. dollar) because the $ symbol is reserved for the
Canadian dollar in the Canadian locale.
public intgeTDefaultFractionDigits()
Returns the default number of fraction digits used with this currency. For
example, the British pound would have a value of 2 because two digits
usually follow the decimal point for pence (such as in £18.29), whereas the
Japanese yen would have zero because yen values typically have no
fractional part (such as ¥1200). Some "currencies" are not really currencies at
all (IMF Special Drawing Rights, for example), and they return 1.
public StringgetCurrencyCode()
Returns the ISO 4217 currency code of this currency.
Exercise 24.2: Select six different locales and six different currencies, and print a table showing the currency
symbol for each currency in each locale.
24.4. Time, Dates, and Calendars
Time is represented as a long integer measured in milliseconds since midnight Greenwich Mean Time (GMT)
January 1, 1970. This starting point for time measurement is known as the epoch. This value is signed, so
negative values signify time before the beginning of the epoch. The System.currentTimeMillis
method returns the current time. This value will express dates into the year A.D. 292,280,995, which should
suffice for most purposes.
You can use java.util.Date to hold a time and perform some simple time-related operations. When a
new Date object is created, you can specify a long value for its time. If you use the no-arg constructor, the
Date object will mark the time of its creation. A Date object can be used for simple operations. For
example, the simplest program to print the current time (repeated from page 37) is
import java.util.Date;
class Date2 {
public static void main(String[] args) {
Date now = new Date();
System.out.println(now);
}
}
This program will produce output such as the following:
Sun Mar 20 08:48:38 GMT+10:00 2005