public static String formatDate(String dateStr, String format) {
        String inputFormat = "yyyy-MM-dd HH:mm:ss";
        if (dateStr == null) {
            return "";
        } else {
            if (dateStr.matches("\\d{1,4}\\-\\d{1,2}\\-\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2}\\.\\d{1,3}")) {
                inputFormat = "yyyy-MM-dd HH:mm:ss.SSS";
            } else if (dateStr.matches("\\d{4}\\-\\d{1,2}\\-\\d{1,2} +\\d{1,2}:\\d{1,2}")) {
                inputFormat = "yyyy-MM-dd HH:mm:ss";
            } else if (dateStr.matches("\\d{4}\\-\\d{1,2}\\-\\d{1,2} +\\d{1,2}:\\d{1,2}")) {
                inputFormat = "yyyy-MM-dd HH:mm";
            } else if (dateStr.matches("\\d{4}\\-\\d{1,2}\\-\\d{1,2} +\\d{1,2}")) {
                inputFormat = "yyyy-MM-dd HH";
            } else if (dateStr.matches("\\d{4}\\-\\d{1,2}\\-\\d{1,2} +\\d{1,2}")) {
                inputFormat = "yyyy-MM-dd";
            } else if (dateStr.matches("\\d{1,4}/\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2}:\\d{1,2}\\.\\d{1,3}")) {
                inputFormat = "yyyy/MM/dd HH:mm:ss.SSS";
            } else if (dateStr.matches("\\d{4}/\\d{1,2}/\\d{1,2} +\\d{1,2}:\\d{1,2}")) {
                inputFormat = "yyyy/MM/dd HH:mm:ss";
            } else if (dateStr.matches("\\d{4}/\\d{1,2}/\\d{1,2} +\\d{1,2}:\\d{1,2}")) {
                inputFormat = "yyyy/MM/dd HH:mm";
            } else if (dateStr.matches("\\d{4}/\\d{1,2}/\\d{1,2} +\\d{1,2}")) {
                inputFormat = "yyyy/MM/dd HH";
            } else if (dateStr.matches("\\d{4}/\\d{1,2}/\\d{1,2} +\\d{1,2}")) {
                inputFormat = "yyyy/MM/dd";
            }

            String resultStr = formatDate(dateStr, inputFormat, format);
            return resultStr;
        }
    }
formatDate

@param dateStr String
@param format String
@return String
inlong-common/src/main/java/org/apache/inlong/common/util/StringUtil.java