Java Utililty Methods LocalDateTime Format

List of utility methods to do LocalDateTime Format

Description

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

Method

LocalDateTimeconvertDateStringToLocalDateTime(String formattedValue, int hour, int minute)
Method that takes a string already preformatted to conform to preferred date format, and returns a LocalDateTime that corresponds to that date, at a specific hour and minute
Objects.requireNonNull(formattedValue);
if ((hour < 0 || hour > 24) || (minute < 0 || minute > 60)) {
    throw new IllegalArgumentException("Illegal argument! Hours and minutes must be in range 0-24, 0-60");
try {
    final LocalDate parsedDate = LocalDate.parse(formattedValue, preferredDateFormat);
    return LocalDateTime.of(parsedDate, LocalTime.of(hour, minute));
} catch (DateTimeParseException e) {
...
StringconvertTemporalToSplunkSearchFormat(OffsetDateTime localDateTime)
convert Temporal To Splunk Search Format
return TIME_SPLUNK_SEARCH_FORMATTER.format(localDateTime);
Stringformat(LocalDateTime dateTime)
format
if (dateTime == null) {
    return null;
return dateTime.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
Stringformat(LocalDateTime localDateTime, String pattern)
format
if (localDateTime == null) {
    return "";
return DateTimeFormatter.ofPattern(pattern == null ? DEFAULT_PATTERN : pattern).format(localDateTime);
StringformatDate(LocalDateTime dateTime)
format Date
return dateTime.format(DateTimeFormatter.ofPattern("dd MMM yyyy"));
StringformatDate(String inPattern, LocalDateTime inTime)
format Date
return formatDate(inPattern, Locale.getDefault(), inTime);
StringformatDateFromTo(LocalDateTime dateFrom, LocalDateTime dateTo)
format Date From To
if (dateFrom == null && dateTo == null) {
    return "";
} else if (dateTo == null) {
    return formatTime(dateFrom);
} else if (dateFrom.isAfter(dateTo)) {
    return formatTime(dateFrom);
} else if (dateFrom.toLocalDate().equals(dateTo.toLocalDate())) {
    return String.format("%s - %s", formatTime(dateFrom), formatTime(dateTo));
...
StringformatDateGeneric(DateTimeFormatter dateTimeFormatter, LocalDateTime localDateTime)
format Date Generic
return localDateTime == null || dateTimeFormatter == null ? "" : localDateTime.format(dateTimeFormatter);
StringformatDateTime(LocalDateTime dateTime)
Returns a string representing dateTime with DATE_TIME_FORMATTER
return dateTime.format(DATE_TIME_FORMATTER);
StringformatDayOfMonth(LocalDateTime dateTime)
format Day Of Month
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_DAY_OF_MONTH);
String formattedDateTime = dateTime.format(formatter);
return formattedDateTime + getDayNumberSuffix(Integer.valueOf(formattedDateTime));