Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Konvertieren von String zu Datum (https://www.delphipraxis.net/182382-konvertieren-von-string-zu-datum.html)

barnti 20. Okt 2014 17:23

Konvertieren von String zu Datum
 
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

Stevie 20. Okt 2014 18:16

AW: Konvertieren von String zu Datum
 
targetDateFormat muss "dd.MM.YYYY" lauten, groß D ist für Day in year

barnti 20. Okt 2014 18:23

AW: Konvertieren von String zu Datum
 
Hallo Stevie,

Zitat:

Zitat von Stevie (Beitrag 1276744)
targetDateFormat muss "dd.MM.YYYY" lauten, groß D ist für Day in year

just in diesem Moment fällt es mir auch auf! Danke für den Anschubser!


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz