Using the Joda-Time 2.4 library. The DateTimeFormat
class is a factory of DateTimeFormatter
formatters. That class offers a forStyle
method to access formatters appropriate to a Locale
.
DateTimeFormatter formatter = DateTimeFormat.forStyle( "MM" ).withLocale( Java.util.Locale.CANADA_FRENCH );
String output = formatter.print( DateTime.now( DateTimeZone.forID( "America/Montreal" ) ) );
The argument with two letters specifies a format for the date portion and the time portion. Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full. A date or time may be ommitted by specifying a style character '-' HYPHEN.
Note that we specified both a Locale and a time zone. Some people confuse the two.
We need all those pieces to properly generate a string representation of a date-time value.