Einzelnen Beitrag anzeigen

barnti

Registriert seit: 15. Aug 2003
Ort: Mal hier mal da...
689 Beiträge
 
Delphi 7 Enterprise
 
#1

Konvertieren von String zu Datum

  Alt 20. Okt 2014, 17:23
Hallo zusammen,

ich habe eine Herausforderung in Java einen String in ein gültiges Datum zu konvertieren. Folgender Code:
Code:
public static String convertAnyDateFormat(String dateString,String sourceDateFormat,String targetDateFormat){
    
      SimpleDateFormat sdf_source = new SimpleDateFormat(sourceDateFormat,Locale.ENGLISH); // Define instance of Source format
      SimpleDateFormat sdf_target = new SimpleDateFormat(targetDateFormat,Locale.ENGLISH); // Define instance of Target format
    
      String var_Date = "";
    
      try{
         var_Date = sdf_target.format(sdf_source.parse(dateString));
      }
      catch(ParseException e){
         System.out.println("Source Format not correct");
      }
    
      return var_Date;
Bei der Eingabe von:
Code:
getDateFromString.convertAnyDateFormat(row2.Date, "EEE MMM dd HH:mm:ss zzzz yyyy", "DD.MM.YYYY");
mit dem Datum "Mon Oct 13 00:00:00 CEST 2014" bekomme ich das Ergebnis "286.10.2014".

Wo ist mein Denkfehler?

Danke
Gruß,

Barnti
  Mit Zitat antworten Zitat