Convert Calendar to String using Apache Commons

This code example shows how to convert a Calendar to a readable String using the Apache Commons Beanutils library. The Beanutils library comes with several converters and one of them is the CalendarConverter.

In the code below we simply create a CalendarConverter object and set the pattern to the format we want the String to be displayed. The pattern follows the standard Java pattern for date and time.
Then we simply call the convert method of the CalendarConverter, sending in the type we want to convert to, in this case the String class, and the value which is our Calendar object that came as a parameter to our doConversion method. Finally we just print out the converted String.

The output format looks like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.