当我尝试使用 Joda 时间执行此代码时出现错误:
// yyyy-mm-dd, also tried 17-Feb-2013
String input = "2013-02-17";
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
DateTime dt = formatter.parseDateTime(input);
TextView tv = (TextView) findViewById(R.id.tvShow);
tv.setText("HERE >>> " + dt.toString());
有任何想法吗?
logcat 说:
03-18 16:58:14.919: W/System.err(8259): java.lang.IllegalArgumentException: Invalid format: "2013-02-17" is malformed at "13-02-17"
03-18 16:58:14.919: W/System.err(8259): at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:871)
03-18 16:58:14.919: W/System.err(8259): at com.example.dateformatter.MainActivity.onCreate(MainActivity.java:42)
03-18 16:58:14.919: W/System.err(8259): at android.app.Activity.performCreate(Activity.java:5163)
03-18 16:58:14.919: W/System.err(8259): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-18 16:58:14.919: W/System.err(8259): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
03-18 16:58:14.919: W/System.err(8259): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-18 16:58:14.919: W/System.err(8259): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-18 16:58:14.919: W/System.err(8259): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-18 16:58:14.927: W/System.err(8259): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 16:58:14.927: W/System.err(8259): at android.os.Looper.loop(Looper.java:137)
03-18 16:58:14.927: W/System.err(8259): at android.app.ActivityThread.main(ActivityThread.java:4895)
03-18 16:58:14.927: W/System.err(8259): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 16:58:14.927: W/System.err(8259): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 16:58:14.927: W/System.err(8259): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-18 16:58:14.927: W/System.err(8259): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-18 16:58:14.927: W/System.err(8259): at dalvik.system.NativeStart.main(Native Method)
03-18 16:58:14.950: D/KeyguardViewMediator(357): setHidden false