Skip to main content
Dates, Numbers, and Currency
- The classes you need to understand are java.util.Date,
java.util.Calendar, java.text.DateFormat, java.text.NumberFormat, and
java.util.Locale.
- Most of the Date class's methods have been deprecated.
- A Date is stored as a long, the number of milliseconds since January 1, 1970.
- Date objects are go-betweens the Calendar and Locale classes.
- The Calendar provides a powerful set of methods to manipulate dates,
performing tasks such as getting days of the week, or adding some
number of months or years (or other increments) to a date.
- Create Calendar instances using static factory methods (getInstance()).
- The Calendar methods you should understand are add(), which allows
you to add or subtract various pieces (minutes, days, years, and so on)
of dates, and roll(), which works like add() but doesn't increment a
date's bigger pieces. (For example: adding 10 months to an October date
changes the month to August, but doesn't increment the Calendar's year
value.)
- DateFormat instances are created using static factory methods (getInstance() and getDateInstance()).
- There are several format "styles" available in the DateFormat class.
- DateFormat styles can be applied against various Locales to create a wide array of outputs for any given date.
- The DateFormat.format() method is used to create Strings containing properly formatted dates.
- The Locale class is used in conjunction with DateFormat and NumberFormat.
- Both DateFormat and NumberFormat objects can be constructed with a specific, immutable Locale.
- For the exam you should understand creating Locales using language, or a combination of language and country