如何使用 SimpleDateFormat outputFormat= new SimpleDateFormat("yyyy-MM-dd") 在 android 中将“2013 年 7 月 15 日”转换为“2013 年 7 月 15 日”;
更新
String dates ="15 July 2013";
try {
String date="15-July-2013";
SimpleDateFormat simpledateFormat = new SimpleDateFormat("dd-MMMM-yyyy");
Date formattedDate=simpledateFormat.parse(date);
SimpleDateFormat newDate =new SimpleDateFormat("yyyy-MM-dd");
String formatDate=newDate.format(formattedDate);
System.out.println("formatDate: "+formatDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
错误日志: 在 java.text.DateFormat.parse(DateFormat.java:626)
07-15 09:46:24.170: W/System.err(23522): at java.text.DateFormat.parse(DateFormat.java:626)
07-15 09:46:24.170: W/System.err(23522): at .CompteCompagnon.onCreate(CompteCompagnon.java:87)
07-15 09:46:24.170: W/System.err(23522): at android.app.Activity.performCreate(Activity.java:5206)
07-15 09:46:24.170: W/System.err(23522): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
07-15 09:46:24.170: W/System.err(23522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-15 09:46:24.170: W/System.err(23522): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-15 09:46:24.170: W/System.err(23522): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-15 09:46:24.170: W/System.err(23522): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-15 09:46:24.170: W/System.err(23522): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 09:46:24.170: W/System.err(23522): at android.os.Looper.loop(Looper.java:137)
07-15 09:46:24.170: W/System.err(23522): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-15 09:46:24.170: W/System.err(23522): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 09:46:24.170: W/System.err(23522): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 09:46:24.170: W/System.err(23522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-15 09:46:24.170: W/System.err(23522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-15 09:46:24.170: W/System.err(23522): at dalvik.system.NativeStart.main(Native Method)