Challenge: Localizing Dates

You may have noticed that, regardless of the device’s locale, the dates displayed in CriminalIntent are always formatted in the default US style, with the month before the day. Take your localization a step further by formatting the dates according to the locale configuration. It is easier than you might think.

Check out the developer documentation on the DateFormat class, which is provided as part of the Android framework. DateFormat provides a date-time formatter that will take into consideration the current locale. You can control the output further by using configuration constants built into DateFormat.

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.