List of utility methods to do DateTimeFormatter
long | convertToEpochMillis(String logTimestamp, DateTimeFormatter logTimeFormat) convert To Epoch Millis ZonedDateTime timestamp = ZonedDateTime.parse(logTimestamp, logTimeFormat);
return timestamp.toInstant().toEpochMilli();
|
DateTimeFormatter | create14DigitDateTimeFormat() create Digit Date Time Format return new DateTimeFormatterBuilder().appendValue(YEAR, 4).appendValue(MONTH_OF_YEAR, 2) .appendValue(DAY_OF_MONTH, 2).appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2) .appendValue(SECOND_OF_MINUTE, 2).toFormatter(Locale.ENGLISH).withZone(ZoneOffset.UTC); |
DateTimeFormatter | createFormatterFromPatternString(String formatPattern, Locale locale) createFormatterFromPatternString, This creates a DateTimeFormatter from the supplied pattern string and supplied locale. DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseLenient().parseCaseInsensitive() .appendPattern(formatPattern).toFormatter(locale); return formatter; |
DateTimeFormatter | dateTimeFormatterNCForPattern(String pattern) date Time Formatter NC For Pattern return DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(TIMEZONE_NOUMEA));
|
String | format(DateTimeFormatter formatter, Object object) Formats a TemporalAccessor object into a String using the specified DateTimeFormatter . return format(formatter, (TemporalAccessor) object);
|
String | format(long epochMilliSecond) format return FORMATTER.format(Instant.ofEpochMilli(epochMilliSecond).atZone(ZoneOffset.UTC));
|
String | formatAgo(long timestamp) format Ago Instant instant = Instant.ofEpochSecond(timestamp / 1000); LocalDateTime local = instant.atZone(Clock.systemUTC().getZone()) .withZoneSameInstant(Clock.systemDefaultZone().getZone()).toLocalDateTime(); return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(local).replaceAll("[T]", " "); |
String | formatByLocale(Date date, Locale locale) format By Locale return formatByLocale(parseToZonedDateTime(date), locale);
|
String | formatDate(long date) format Date if (dateTimeFormatter == null) dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); return LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()).format(dateTimeFormatter); |
String | formatDate(long milli) format Date return DateTimeFormatter.ISO_LOCAL_DATE.format(Instant.ofEpochMilli(milli).atOffset(ZERO));
|