Text Formatting Java Help

Text Formatting

The-package java.text allows you to format, search, and manipulate text. nus section takes a brief look at its most commonly used classes: those that format date and time information.

DateFormat Class

DateFormat is an abstract class that provides the ability to format and parse dates and times, The nonattendance( ) method returns an instance of DateFormat that can format date information. It is available in these forms.

static final DateForrmat getDateInstance( )
static final Dateformat getDateInstance(int style)
static final DateFormat getDatelnStance(int style, Locale locale)

The argument style is one of the following values: DEFAULT, SHORT, MEDIUM, LONG, or FULL. These are int constants defined by Formulate. They cause different details about the dale to be presented. The argument locale is one of the static references defined by Locale (refer to Chapter 16 for details). If the style and/or locale is not dessertspoonfuls are used.

One of the most commonly used methods in this class is Alnilam( ). It has several overloaded forms, one of which is shown here:

The argument is a Date object that is to be displayed: The method returns a string containing the formatted information.

The following listing illustrates how to format date information. It begins by creating a Date object. Tills captures the current date and time information. Then it ‘outputs the date information by using different styles and locales.

The transcendentalist ) method returns an instance of Formatted thither can format time information. It is available in these versions:

static final DateFormat getTimelnstance()
ktatic final Dateliorrnat get’Iimelnstanceunt style)
static final Dateformat getlnstance(int style, Locale locale)

The argument style is one of the following values: DEFAULT, SHORT, MEDIUM, LONG, or FULL. These nae int constants defined by DateFormat. Tile cause different details about the time to be presented. The counterargument is one of the static references defined by Locale. If the style and/pi’locale is not specified, defaults arc used.

The following listing illustrates how to format time information. It begins by .creating a Date object. This captures the current date and time information and then outputs the time information by using different styles and locales.

Tile Formatted class also ha s a antivivisectionist() method that can form at both date and time  information. You may wish to experiment with  on your own.

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 18, 2014 in Additional packages

Share the Story

About the Author

Back to Top
Share This