Skip to content

Instantly share code, notes, and snippets.

@gevorg
Created October 21, 2017 08:21
Show Gist options
  • Save gevorg/e1d1ffeefd25eb172ba1671fcba2df2a to your computer and use it in GitHub Desktop.
Save gevorg/e1d1ffeefd25eb172ba1671fcba2df2a to your computer and use it in GitHub Desktop.
Custom month name java8
def monthNameMap = [1L: "MIK", 2L: "PIK", 3L: "CIK"]
LocalDate date = LocalDate.now()
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("yyyy ")
.appendText(ChronoField.MONTH_OF_YEAR, monthNameMap)
.toFormatter(Locale.FRENCH)
for (int i = 0; i < 12; ++i) {
date = date.minusMonths(1)
println formatter.format(date)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment