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

InstantfromInfluxDBTimeFormat(final String timestamp)
from Influx DB Time Format
return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(timestamp));
OptionalfromString(String dateString, DateTimeFormatter formatter)
from String
if (dateString == null || formatter == null)
    return Optional.empty();
try {
    return Optional.of(ZonedDateTime.parse(dateString, formatter));
} catch (DateTimeParseException e) {
    return Optional.empty();
DateTimeFormattergetDateFormat()
get Date Format
return DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
DateTimeFormattergetDateFormat(final Locale LOCALE)
get Date Format
if (Locale.US == LOCALE) {
    return DateTimeFormatter.ofPattern("MM/dd/YYYY");
} else if (Locale.CHINA == LOCALE) {
    return DateTimeFormatter.ofPattern("YYYY.MM.dd");
} else {
    return DateTimeFormatter.ofPattern("dd.MM.YYYY");
DategetDateFromFormat(String dtStr)
Expects date string as MM-dd-yyyy
LocalDate ld = LocalDate.parse(dtStr, df2);
return localDateToSystemAdjustedStartOfDayDate(ld);
DateTimeFormattergetDateTimeAttributeTimeFormat()
Get a DateTimeFormatter to use for rendering time information within a time tag's datetime attribute
return DateTimeFormatter.ofPattern("hh:mm a");
DateTimeFormattergetDateTimeFormatter()
Returns the date time formatter used to parse date strings.
if (dateTimeTZFormat == null) {
    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    DateTimeFormatter optionalTime = DateTimeFormatter.ofPattern(" HH:mm:ss");
    DateTimeFormatter optionalSec = DateTimeFormatter.ofPattern(".SSS");
    DateTimeFormatter optionalZone = DateTimeFormatter.ofPattern(" ZZZ");
    dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime)
            .appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
return dateTimeTZFormat;
StringgetFormatDate(String format)
get Format Date
return getFormatDate(format, new Date());
StringgetFormattedDate()
get Formatted Date
return formatDate(getCurrentDate(), PATTERN_DEFAULT);
StringgetFormattedDateString()
get Formatted Date String
LocalDateTime currentTime = LocalDateTime.now();
return currentTime.format(DateTimeFormatter.ISO_LOCAL_DATE);