Java LocalDateTime Format formatDate(String inPattern, LocalDateTime inTime)

Here you can find the source of formatDate(String inPattern, LocalDateTime inTime)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(String inPattern, LocalDateTime inTime) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

import java.util.HashMap;

import java.util.Locale;
import java.util.Map;

public class Main {
    private static final Map<String, DateTimeFormatter> DATETIMEFORMATTERS = new HashMap<>();

    public static String formatDate(String inPattern, LocalDateTime inTime) {
        return formatDate(inPattern, Locale.getDefault(), inTime);
    }/* w  ww  .j ava  2 s . c om*/

    public static String formatDate(String inPattern, Locale inLocale, LocalDateTime inTime) {

        if (inPattern == null || inTime == null) {

            return null;
        }

        DateTimeFormatter theDtf = DATETIMEFORMATTERS.get(inPattern);

        if (theDtf == null) {

            DATETIMEFORMATTERS.put(inPattern,
                    theDtf = new DateTimeFormatterBuilder().appendPattern(inPattern).toFormatter(inLocale));
        }

        return theDtf.format(inTime);
    }
}

Related

  1. convertDateStringToLocalDateTime(String formattedValue, int hour, int minute)
  2. convertTemporalToSplunkSearchFormat(OffsetDateTime localDateTime)
  3. format(LocalDateTime dateTime)
  4. format(LocalDateTime localDateTime, String pattern)
  5. formatDate(LocalDateTime dateTime)
  6. formatDateFromTo(LocalDateTime dateFrom, LocalDateTime dateTo)
  7. formatDateGeneric(DateTimeFormatter dateTimeFormatter, LocalDateTime localDateTime)
  8. formatDateTime(LocalDateTime dateTime)
  9. formatDayOfMonth(LocalDateTime dateTime)