Java Code Examples for java.time.format.DateTimeFormatter#ISO_TIME
The following examples show how to use
java.time.format.DateTimeFormatter#ISO_TIME .
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: Jsr310DateTimeFormatAnnotationFormatterFactory.java From spring-analysis-note with MIT License | 6 votes |
@Override public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) { DateTimeFormatter formatter = getFormatter(annotation, fieldType); // Efficient ISO_LOCAL_* variants for printing since they are twice as fast... if (formatter == DateTimeFormatter.ISO_DATE) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE; } } else if (formatter == DateTimeFormatter.ISO_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_TIME; } } else if (formatter == DateTimeFormatter.ISO_DATE_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; } } return new TemporalAccessorPrinter(formatter); }
Example 2
Source File: Jsr310DateTimeFormatAnnotationFormatterFactory.java From java-technology-stack with MIT License | 6 votes |
@Override public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) { DateTimeFormatter formatter = getFormatter(annotation, fieldType); // Efficient ISO_LOCAL_* variants for printing since they are twice as fast... if (formatter == DateTimeFormatter.ISO_DATE) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE; } } else if (formatter == DateTimeFormatter.ISO_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_TIME; } } else if (formatter == DateTimeFormatter.ISO_DATE_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; } } return new TemporalAccessorPrinter(formatter); }
Example 3
Source File: PutSQL.java From localization_nifi with Apache License 2.0 | 6 votes |
private DateTimeFormatter getDateTimeFormatter(String pattern) { switch(pattern) { case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE; case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE; case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE; case "ISO_DATE": return DateTimeFormatter.ISO_DATE; case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME; case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME; case "ISO_TIME": return DateTimeFormatter.ISO_TIME; case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME; case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME; case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME; case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME; case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE; case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE; case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT; case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME; default: return DateTimeFormatter.ofPattern(pattern); } }
Example 4
Source File: Jsr310DateTimeFormatAnnotationFormatterFactory.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) { DateTimeFormatter formatter = getFormatter(annotation, fieldType); // Efficient ISO_LOCAL_* variants for printing since they are twice as fast... if (formatter == DateTimeFormatter.ISO_DATE) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE; } } else if (formatter == DateTimeFormatter.ISO_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_TIME; } } else if (formatter == DateTimeFormatter.ISO_DATE_TIME) { if (isLocal(fieldType)) { formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; } } return new TemporalAccessorPrinter(formatter); }
Example 5
Source File: JdbcCommon.java From nifi with Apache License 2.0 | 6 votes |
public static DateTimeFormatter getDateTimeFormatter(String pattern) { switch(pattern) { case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE; case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE; case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE; case "ISO_DATE": return DateTimeFormatter.ISO_DATE; case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME; case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME; case "ISO_TIME": return DateTimeFormatter.ISO_TIME; case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME; case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME; case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME; case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME; case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE; case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE; case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT; case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME; default: return DateTimeFormatter.ofPattern(pattern); } }
Example 6
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 7
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 8
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 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: LocalTimeConverter.java From sailfish-core with Apache License 2.0 | 4 votes |
@Override protected DateTimeFormatter getFormatter() { return DateTimeFormatter.ISO_TIME; }
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); }