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

StringformatLocalDateTimeToString(LocalDateTime date)
Formats a LocalDateTime into a string
return date.format(localDateTimeFormatter);
StringformatShortDate(LocalDateTime dateTime)
format Short Date
if (dateTime == null) {
    return null;
LocalDate date = dateTime.toLocalDate();
long daysDifference = LocalDate.now().until(date, ChronoUnit.DAYS);
String dateFormat;
if (daysDifference >= 2 && daysDifference <= 6) {
    dateFormat = "dd MMM";
...
StringformattedWeek(LocalDateTime localDateTime)
formatted Week
return String.format("%04d-%02d", localDateTime.getYear(),
        localDateTime.get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear()));
StringformatTime(LocalDateTime dateTime)
format Time
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_TIME);
return dateTime.format(formatter);
StringformatTime(LocalDateTime time)
format Time
return String.join(timeDelimiter, String.format("%02d", time.getHour()),
        String.format("%02d", time.getMinute()), String.format("%02d", time.getSecond()));
StringlocalDateTime2Str(LocalDateTime localDateTime, String dateTimeFormatter)
local Date Time Str
return localDateTime.format(DateTimeFormatter.ofPattern(dateTimeFormatter));
StringtoDoubleExcelFormat(LocalDateTime date, boolean date1904)
to Double Excel Format
if (date == null)
    return "";
LocalDateTime from;
if (date1904) {
    from = LocalDateTime.of(1904, 1, 1, 0, 0, 0);
} else {
    from = LocalDateTime.of(1900, 1, 1, 0, 0, 0);
    if (date.isBefore(LocalDateTime.of(1900, 3, 1, 0, 0, 0))) {
...
LocalDateTimetoLocalDateTime(String date, DateTimeFormatter formatter)
to Local Date Time
try {
    ZonedDateTime zonedDateTime = toZonedDateTime(date, formatter);
    return LocalDateTime.ofInstant(zonedDateTime.toInstant(), ZoneId.systemDefault());
} catch (Exception e) {
    throw new IllegalArgumentException(e);
StringtoString(LocalDateTime ldt, DateTimeFormatter formatter)
to String
return ldt == null ? "" : ldt.format(formatter);