Home » text

Tag Archives: text

Format number with custom NumberFormat

In this example we shall show you how to format a number with a custom NumberFormat. NumberFormat provides the interface for formatting and parsing numbers. It also provides methods for determining which locales have number formats, and what their names are. To format a number with custom NumberFormat one should perform the following steps: Create a new DecimalFormat, using a ...

Read More »

Parse custom formatted date with SimpleDateFormat

With this example we are going to demonstrate how to parse custom formatted date with SimpleDateFormat. SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows formatting (date -> text), parsing (text -> date), and normalization. In short, to parse custom formatted date with SimpleDateFormat you should: Create a new SimpleDateFormat, using a String ...

Read More »

Format date in custom formats with SimpleDateFormat

This is an example of how to format a Date in custom formats, with the SimpleDateFormat. SimpleDateFormat can be used to format and parse dates. Formating a Date in custom format with the SimpleDateFormat implies that you should: Create a new Date. Create a new SimpleDateFormat, using a String pattern. The pattern describes the date and time format. Invoke the ...

Read More »

Convert dates between formats with SimpleDateFormat

In this example we shall show you how to convert dates between formats with SimpleDateFormat. To convert dates between formats with SimpleDateFormat one should perform the following steps: Create a new String to be used as the date that will be parsed by the SimpleDateFormat. Create a new SimpleDateFormat, using a String pattern to describe the date and time format. ...

Read More »

Format date in default formats with DateFormat

With this example we are going to demonstrate how to format a date in default formats with DateFormat. Default formats are provided by the DateFormat API to control the length of the result, from SHORT, MEDIUM to LONG and FULL. In short, to format a date in default formats with DateFormat you should: Create a new Date. For each one ...

Read More »

Convert String to Date with DateFormat

This is an example of how to convert a String to Date with DateFormat. As the Java API documentation states Date formats are not synchronized, so it is recommended to create separate format instances for each thread. Below are three examples of creating separate instances of DateFormat. The “getDateInstance(..)” approach implies that you should invoke the getDateInstance(int style) API method, ...

Read More »