O'Reilly logo

Core Java® Volume II—Advanced Features, Ninth Edition by Gary Cornell, Cay S. Horstmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.3. Date and Time

When you are formatting date and time, you should be concerned with four locale-dependent issues:

• The names of months and weekdays should be presented in the local language.

• There will be local preferences for the order of year, month, and day.

• The Gregorian calendar might not be the local preference for expressing dates.

• The time zone of the location must be taken into account.

The Java DateFormat class handles these issues. It is easy to use and quite similar to the NumberFormat class. First, get a locale. You can use the default locale or call the static getAvailableLocales method to obtain an array of locales that support date formatting. Then, call one of the three factory methods:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required