List of usage examples for java.time.format DecimalStyle of
public static DecimalStyle of(Locale locale)
From source file:Main.java
/** * Parses a String to a ChronoLocalDate using a DateTimeFormatter with a short * pattern based on the current Locale and the provided Chronology, then * converts this to a LocalDate (ISO) value. * * @param text//from ww w . jav a 2s.c om * - the input date text in the SHORT format expected for the * Chronology and the current Locale. * * @param chrono * - an optional Chronology. If null, then IsoChronology is used. */ public static LocalDate fromString(String text, Chronology chrono) { if (text != null && !text.isEmpty()) { Locale locale = Locale.getDefault(Locale.Category.FORMAT); if (chrono == null) { chrono = IsoChronology.INSTANCE; } String pattern = "M/d/yyyy GGGGG"; DateTimeFormatter df = new DateTimeFormatterBuilder().parseLenient().appendPattern(pattern) .toFormatter().withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale)); TemporalAccessor temporal = df.parse(text); ChronoLocalDate cDate = chrono.date(temporal); return LocalDate.from(cDate); } return null; }