Java Code Examples for java.time.format.DateTimeFormatter#ofLocalizedDate()
The following examples show how to use
java.time.format.DateTimeFormatter#ofLocalizedDate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeFormatterRegistrar.java From spring-analysis-note with MIT License | 5 votes |
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); } }
Example 2
Source File: DateTimeFormatterFactory.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use * when no specific factory properties have been set * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { // Using strict parsing to align with Joda-Time and standard DateFormat behavior: // otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected. // However, with strict parsing, a year digit needs to be specified as 'u'... String patternToUse = StringUtils.replace(this.pattern, "yy", "uu"); dateTimeFormatter = DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = DateTimeFormatter.ISO_DATE; break; case TIME: dateTimeFormatter = DateTimeFormatter.ISO_TIME; break; case DATE_TIME: dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME; break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (this.dateStyle != null && this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle); } else if (this.dateStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle); } else if (this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId()); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 3
Source File: DateTimeFormatterRegistrar.java From java-technology-stack with MIT License | 5 votes |
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); } }
Example 4
Source File: DateTimeFormatterFactory.java From java-technology-stack with MIT License | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use * when no specific factory properties have been set * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { // Using strict parsing to align with Joda-Time and standard DateFormat behavior: // otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected. // However, with strict parsing, a year digit needs to be specified as 'u'... String patternToUse = StringUtils.replace(this.pattern, "yy", "uu"); dateTimeFormatter = DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = DateTimeFormatter.ISO_DATE; break; case TIME: dateTimeFormatter = DateTimeFormatter.ISO_TIME; break; case DATE_TIME: dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME; break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (this.dateStyle != null && this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle); } else if (this.dateStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle); } else if (this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId()); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 5
Source File: DateTimeFormatterRegistrar.java From lams with GNU General Public License v2.0 | 5 votes |
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); } }
Example 6
Source File: DateTimeFormatterRegistrar.java From spring4-understanding with Apache License 2.0 | 5 votes |
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); } }
Example 7
Source File: DateTimeFormatterFactory.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use when no specific * factory properties have been set (can be {@code null}). * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormatter.ofPattern(this.pattern); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = DateTimeFormatter.ISO_DATE; break; case TIME: dateTimeFormatter = DateTimeFormatter.ISO_TIME; break; case DATE_TIME: dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME; break; case NONE: /* no-op */ break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (this.dateStyle != null && this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle); } else if (this.dateStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle); } else if (this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId()); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 8
Source File: BattleLogs.java From logbook-kai with MIT License | 5 votes |
/** * 任意期間の集計単位 * * @param from 期間の開始日付 * @param to 期間の終了日付 */ public CustomUnit(LocalDate from, LocalDate to) { DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); // 単位の名前 // yy/MM/dd-yy/MM/dd(xx日) this.name = formatter.format(from) + "-" + formatter.format(to) + "(" + ((to.toEpochDay() - from.toEpochDay()) + 1) + "日)"; // 期間の開始 this.from = ZonedDateTime.of(LocalDateTime.of(from, LocalTime.MIN), ZoneId.of("GMT+04:00")); // 期間の終了 this.to = ZonedDateTime.of(LocalDateTime.of(to, LocalTime.MAX), ZoneId.of("GMT+04:00")); }
Example 9
Source File: DateTimeFormater.java From JavaSE8-Features with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { LocalDate currentDate = LocalDate.now(); DateTimeFormatter df = DateTimeFormatter.ISO_DATE; System.out.println(df.format(currentDate)); LocalTime currentTime = LocalTime.now(); DateTimeFormatter dt = DateTimeFormatter.ISO_TIME; System.out.println(dt.format(currentTime)); LocalDateTime currentDT = LocalDateTime.now(); DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME; System.out.println(dtf.format(currentDT)); DateTimeFormatter f_long = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); System.out.println(f_long.format(currentDT)); DateTimeFormatter f_short = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); System.out.println(f_short.format(currentDT)); String fr_short = f_short.withLocale(Locale.FRENCH).format(currentDT); String fr_long = f_long.withLocale(Locale.FRENCH).format(currentDT); System.out.println(fr_short); System.out.println(fr_long); DateTimeFormatterBuilder b = new DateTimeFormatterBuilder() .appendValue(ChronoField.DAY_OF_YEAR) .appendLiteral("||") .appendValue(ChronoField.DAY_OF_MONTH) .appendLiteral("||") .appendValue(ChronoField.YEAR); DateTimeFormatter f = b.toFormatter(); System.out.println(f.format(currentDT)); }
Example 10
Source File: ODateLabel.java From Orienteer with Apache License 2.0 | 5 votes |
private DateTimeFormatter getFormatter(ZoneId zoneId) { DateTimeFormatter formatter; if (showTime) { formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); } else formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); return formatter.withLocale(getLocale()) .withZone(convertTimeZone&&zoneId!=null ?zoneId :OrienteerWebSession.get().getDatabase().getStorage() .getConfiguration().getTimeZone().toZoneId()); }
Example 11
Source File: DateTimeFormatterFactory.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use when no specific * factory properties have been set (can be {@code null}). * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { // Using strict parsing to align with Joda-Time and standard DateFormat behavior: // otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected. // However, with strict parsing, a year digit needs to be specified as 'u'... String patternToUse = this.pattern.replace("yy", "uu"); dateTimeFormatter = DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = DateTimeFormatter.ISO_DATE; break; case TIME: dateTimeFormatter = DateTimeFormatter.ISO_TIME; break; case DATE_TIME: dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME; break; case NONE: /* no-op */ break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (this.dateStyle != null && this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle); } else if (this.dateStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle); } else if (this.timeStyle != null) { dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId()); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 12
Source File: LocalDateDatatype.java From cuba with Apache License 2.0 | 4 votes |
@Override protected DateTimeFormatter getDateTimeFormatter() { return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); }
Example 13
Source File: EmailService.java From waltz with Apache License 2.0 | 4 votes |
private void sendAttestationRunNotification(EntityReference ref) { DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); AttestationRun run = attestationRunDao.getById(ref.id()); List<String> recipients = attestationInstanceRecipientDao.findRecipientsByRunId(run.id().get()); List<AttestationInstance> instances = attestationInstanceDao.findByRunId(ref.id()); List<String> recipientEmails = recipients.stream() .distinct() .collect(toList()); List<String> applications = instances .stream() .map(d -> d.parentEntity()) .filter(r -> r.kind().equals(EntityKind.APPLICATION)) .map(r -> r.name()) .filter(n -> n.isPresent()) .map(n -> n.get()) .distinct() .collect(toList()); String subject = "Waltz attestation: " + run.name(); String attestationsUrl = baseUrl + "/attestation/instance/user"; String body = "You are required to attest correctness of the applications listed below:" + MAIL_NEW_LINE + MAIL_NEW_LINE + "<strong>Application(s):</strong> " + String.join(", ", applications) + MAIL_NEW_LINE + MAIL_NEW_LINE + "<strong>Due Date:</strong> " + run.dueDate().format(DATE_TIME_FORMATTER) + MAIL_NEW_LINE + MAIL_NEW_LINE + run.description() + MAIL_NEW_LINE + MAIL_NEW_LINE + "Please use this URL to view your pending attestations: " + attestationsUrl; sendEmailNotification(subject, body, recipientEmails); }
Example 14
Source File: LocalDateRenderer.java From flow with Apache License 2.0 | 2 votes |
/** * Creates a new LocalDateRenderer. * <p> * The renderer is configured with the format style {@code FormatStyle.LONG} * and an empty string as its null representation. * * @param valueProvider * the callback to provide a {@link LocalDate} to the renderer, * not <code>null</code> * * @see <a href= * "https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html#LONG"> * FormatStyle.LONG</a> */ public LocalDateRenderer(ValueProvider<SOURCE, LocalDate> valueProvider) { this(valueProvider, DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG), ""); }