25 lines
852 B
Java
25 lines
852 B
Java
package Date;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
public class DateFormatConverter {
|
|
public static String convertDate(String inputDate) {
|
|
try {
|
|
Date date = new SimpleDateFormat("dd.MM.yyyy").parse(inputDate);
|
|
return new SimpleDateFormat("yyyy-MM-dd").format(date);
|
|
} catch (Exception e) {
|
|
System.err.println("Fehler beim Konvertieren des Datums: " + e.getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
String inputDate = "25.04.2024";
|
|
String convertedDate = convertDate(inputDate);
|
|
if (convertedDate != null) {
|
|
System.out.println("Ursprüngliches Datum: " + inputDate);
|
|
System.out.println("Konvertiertes Datum: " + convertedDate);
|
|
}
|
|
}
|
|
}
|