javajodatimedatetime-format

DateTimeFormat.forPattern won't use text for month


It's documented here that using the string "MMM" for the month, a text is used and not a number:

Month: 3 or over, use text, otherwise use number.

I'm doing DateTimeFormat.forPattern( "dd/MMM/yyyy" ).print( DateTime.now() ) and instead of returning 05/Apr/2016, it's returning 05/4/2016.

How can I make it return the month in a text format?

Java 6


Solution

  • This solves the problem:

    DateTimeFormat.forPattern( "dd/MMM/yyyy" ).withLocale( Locale.US ).print( DateTime.now() )
    

    Now I'm getting 05/Apr/2016