Jim
Jim

Reputation: 19552

Get month and year from Joda's LocalDate

From a LocalDate I want to get only the month-year string.
E.g “March 2015” Right now I do it as follows:

myDate.monthOfYear().getAsText(LOCALE) + " " + myDate.year().getAsText(LOCALE);

Is there a simpler/better way to do it?

Upvotes: 0

Views: 1733

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500035

Yes - just create an appropriate formatter:

DateTimeFormatter formatter = DateTimeFormat
    .forPattern("MMMM yyyy")
    .withLocale(LOCALE);

String text = formatter.print(myDate);

Upvotes: 2

Related Questions