Thomas Rasmussen
09/02/2025, 8:16 PMDate.parse('yyyy-MMM', '2011-Okt')
java.text.ParseException: Unparseable date: "2011-Okt"
Java changed date parsing in Java 9, I have found answers suggesting setting -Djava.locale.providers=COMPAT,SPI,CLDR should bring back support for Java 8 formats - but it doesn't seam to work...
Will I have to rewrite the code, or is there a JVM setting I am missing?jonnybot
09/03/2025, 7:30 PMprintln System.getProperty("java.version")
Date.parse('yyyy-MMM', '2011-Okt')
puts out:
1.8.0_412
Exception thrown
java.text.ParseException: Unparseable date: "2011-Okt"
at ConsoleScript2.run(ConsoleScript2:2)
I reckon you'll be best off using LocalDate. Something like:
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder
import java.time.format.ResolverStyle
import java.time.temporal.ChronoField
Locale da = Locale.forLanguageTag('da-DK')
DateTimeFormatter ymDa = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern('uuuu')
.optionalStart()
.appendLiteral('-')
.appendPattern('MMM')
.optionalEnd()
.parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
.parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
.toFormatter(da)
.withResolverStyle(ResolverStyle.STRICT)
LocalDate.parse('2011-okt.', ymDa)
Though I think (based on some searching and LLM bashing) that 2011-Okt might actually be a German locale format, not a Danish one.Thomas Rasmussen
09/05/2025, 8:07 AM