wie erstellen Date-Objekt aus dem String-Wert

Beim laufen durch den folgenden code erhalte ich eine UNPARSABLE DATE EXCEPTION.

Wie kann ich dieses Problem beheben?

   package dateWork;

    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    public class DateCreation {

        /**
         * @param args
         */
        public static void main(String[] args) {

            String startDateString = "2013-03-26";
            DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); 
            Date startDate=null;
            String newDateString = null;
            try 
            {
                startDate = df.parse(startDateString);
                newDateString = df.format(startDate);
                System.out.println(startDate);
            } catch (ParseException e) 
            {
                e.printStackTrace();
            }
        }

    }
Hinweis Sie haben 2 Formate für Datum drin, sondern nur ein " = SimpleDateFormat
Versuchen -: String startDateString = "2013-03-26"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

InformationsquelleAutor Hussain Akhtar Wahid 'Ghouri' | 2013-04-02

Schreibe einen Kommentar