@@ -223,32 +223,6 @@ public static String getCurrentDate(ZoneIds zoneId) {
223223 return dtf .format (now );
224224 }
225225
226- /**
227- * Formats a date string from an automatically detected input format to a
228- * user-specified output format.
229- *
230- * @param input The date string to format.
231- * @param outputFormat The desired output format string (e.g., "yyyy-MM-dd").
232- * @return The formatted date string, or the original input string if the
233- * input format cannot be detected.
234- */
235- public static String fixDateFormat (String input , String outputFormat ) {
236- String [] SUPPORTED_INPUT_FORMATS = {
237- "yyyy-M-dd" , "yyyy-MM-dd" , "M/d/yyyy" , "MM/d/yyyy" , "yyyy/M/d" , "yyyy/MM/d" ,
238- "M-d-yyyy" , "MM-d-yyyy" , "yyyy-M-d" , "yyyy-MM-d"
239- };
240- for (String inputFormat : SUPPORTED_INPUT_FORMATS ) {
241- try {
242- SimpleDateFormat simpleDateFormat = new SimpleDateFormat (inputFormat );
243- Date date = simpleDateFormat .parse (input );
244- SimpleDateFormat outputSimpleDateFormat = new SimpleDateFormat (outputFormat );
245- return outputSimpleDateFormat .format (date );
246- }
247- catch (ParseException ignored ) {}
248- }
249- return input ;
250- }
251-
252226 /**
253227 * Formats a date string from a specified input format to a desired output format.
254228 *
@@ -268,4 +242,25 @@ public static String fixDateFormat(String input, String inputFormat, String outp
268242 }
269243 catch (ParseException exception ) {throw new RuntimeException (exception );}
270244 }
245+
246+ /**
247+ * Formats a date string from an automatically detected input format to a
248+ * user-specified output format.
249+ *
250+ * @param input The date string to format.
251+ * @param outputFormat The desired output format string (e.g., "yyyy-MM-dd").
252+ * @return The formatted date string, or the original input string if the
253+ * input format cannot be detected.
254+ */
255+ public static String fixDateFormat (String input , String outputFormat ) {
256+ String [] SUPPORTED_INPUT_FORMATS = {
257+ "yyyy-M-dd" , "yyyy-MM-dd" , "M/d/yyyy" , "MM/d/yyyy" , "yyyy/M/d" , "yyyy/MM/d" ,
258+ "M-d-yyyy" , "MM-d-yyyy" , "yyyy-M-d" , "yyyy-MM-d"
259+ };
260+ for (String inputFormat : SUPPORTED_INPUT_FORMATS ) {
261+ try {return fixDateFormat (input , inputFormat , outputFormat );}
262+ catch (Exception ignored ) {}
263+ }
264+ return input ;
265+ }
271266}
0 commit comments