/** * Get a {@link DateFormat} for {@link Date} formatting and set it up according to context {@link Locale} and * {@link Localization} settings, using default format styles. * @param type Temporal type * @return DateFormat * @throws LocalizationException If context is not localized */ default DateFormat getDateFormat(TemporalType type) { return getDateFormat(type, null, null); }
public void localization() { // tag::localization[] LocalizationContext ctx = LocalizationContext.builder() .withMessageProvider(MessageProvider.fromProperties("messages").build()).withInitialLocale(Locale.US) .build(); ctx.getLocale().ifPresent(l -> System.out.println(l)); // <1> String localizedMessage = ctx.getMessage("test.message", "defaultMessage"); // <2> localizedMessage = ctx .getMessage(Localizable.builder().message("defaultMessage").messageCode("test.message").build()); // <3> ctx.format(2.56); // <4> ctx.format(0.5, NumberFormatFeature.PERCENT_STYLE); // <5> ctx.format(5600.678, 2); // <6> NumberFormat nf = ctx.getNumberFormat(Integer.class); // <7> ctx.format(new Date(), TemporalType.DATE); // <8> ctx.format(new Date(), TemporalType.DATE_TIME, TemporalFormat.LONG, TemporalFormat.LONG); // <9> ctx.format(LocalDate.of(2017, Month.MARCH, 15)); // <10> ctx.format(LocalDateTime.of(2017, Month.MARCH, 15, 16, 48), TemporalFormat.FULL, TemporalFormat.SHORT); // <11> DateFormat df = ctx.getDateFormat(TemporalType.DATE); // <12> DateTimeFormatter dtf = ctx.getDateTimeFormatter(TemporalType.DATE_TIME); // <13> // end::localization[] }