Formatting Dates and Times

Just as it is possible to format numbers and currency, it is possible with classes from java.text to format dates and times.

Date and Time Using DateFormat: Code Example

The principles are essentially the same as formatting numbers, so I'll get right to the code. Listing 18.5 shows how to format dates and times using both predefined, locale-sensitive formats, and creating custom formats for locale-independent formats.

Code Listing 18.5. Using DateFormat and SimpleDateFormat (TextDriver3.java)
 // Program to format data with help from java.text import java.text.*; import java.util.*; class DateShaper { Locale usLocale; Locale deLocale; DateFormat usDateFormatter; DateFormat deDateFormatter; String formattedDate; Date ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.