Java Utililty Methods DateTimeFormatter

List of utility methods to do DateTimeFormatter

Description

The list of methods to do DateTimeFormatter are organized into topic(s).

Method

longconvertToEpochMillis(String logTimestamp, DateTimeFormatter logTimeFormat)
convert To Epoch Millis
ZonedDateTime timestamp = ZonedDateTime.parse(logTimestamp, logTimeFormat);
return timestamp.toInstant().toEpochMilli();
DateTimeFormattercreate14DigitDateTimeFormat()
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);
DateTimeFormattercreateFormatterFromPatternString(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;
DateTimeFormatterdateTimeFormatterNCForPattern(String pattern)
date Time Formatter NC For Pattern
return DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(TIMEZONE_NOUMEA));
Stringformat(DateTimeFormatter formatter, Object object)

Formats a TemporalAccessor object into a String using the specified DateTimeFormatter .

return format(formatter, (TemporalAccessor) object);
Stringformat(long epochMilliSecond)
format
return FORMATTER.format(Instant.ofEpochMilli(epochMilliSecond).atZone(ZoneOffset.UTC));
StringformatAgo(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]", " ");
StringformatByLocale(Date date, Locale locale)
format By Locale
return formatByLocale(parseToZonedDateTime(date), locale);
StringformatDate(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);
StringformatDate(long milli)
format Date
return DateTimeFormatter.ISO_LOCAL_DATE.format(Instant.ofEpochMilli(milli).atOffset(ZERO));