Convert string to Date in java

前端 未结 6 1396
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 02:30

I\'m trying to parse a string to a date field in an android application but I can\'t seem to get it correct. Here is the string I\'m trying to convert to a date \"03/26/2012

6条回答
  •  [愿得一人]
    2020-11-30 03:03

    You are wrong in the way you display the data I guess, because for me:

        String dateString = "03/26/2012 11:49:00 AM";
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");
        Date convertedDate = new Date();
        try {
            convertedDate = dateFormat.parse(dateString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(convertedDate);
    

    Prints:

    Mon Mar 26 11:49:00 EEST 2012
    

提交回复
热议问题