Ich versuche April 18 2016 10:41 AM
-04/18/2016 10:41
zu analysieren. Hier ist mein CodeDatumsformat in Android von 18. April 2016 10.41 bis 2016.04.18 10.41
private String dateFormat(String strCurrentDate) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("mmmm dd yyyy hh:mm Z");
Date newDate = null;
newDate = format.parse(strCurrentDate);
format = new SimpleDateFormat("MM/dd/yyyy hh:mm");
String date = format.format(newDate);
Log.d("DATE_FORMATE_TESTING", date);
return date;
}
Aber es gibt die folgenden Fehler
04-18 10:41:43.834 7526-7526/gps.clock.com W/System.err: java.text.ParseException: Unparseable date: "April 18 2016 01:41 PM" (at offset 0)
04-18 10:41:43.834 7526-7526/gps.clock.com W/System.err: at java.text.DateFormat.parse(DateFormat.java:579)
04-18 10:41:43.834 7526-7526/gps.clock.com W/System.err: at gps.clock.com.MainActivity.dateFormat(MainActivity.java:441)
04-18 10:41:43.834 7526-7526/gps.clock.com W/System.err: at gps.clock.com.MainActivity.access$500(MainActivity.java:70)
04-18 10:41:43.834 7526-7526/gps.clock.com W/System.err: at gps.clock.com.MainActivity$1$4.onClick(MainActivity.java:303)
Kann mir jemand sagen, wie soll ich es beheben? Warum zeigt es Unparseable date
. Wie soll ich es analysieren? Vielen Dank im Voraus.
sind Sie Eibisch mit? –
Sie haben Kleinbuchstaben für den Monat im ersten Muster. Sie sollten in Großbuchstaben geschrieben sein. Und der Charakter für am/pm ist 'a', nicht' Z'. Bitte beachten Sie die [ 'SimpleDateFormat' docs] (http://developer.android.com/reference/java/text/SimpleDateFormat.html) –
Mögliches Duplikat [falscher Konvertierung von String in dem Datumsformat] (http: // Stackoverflow .com/questions/13698165/Inkorrektes Konvertieren von String-in-Datum-Format) –