我尝试从Android中的edittext获取日期,但代码返回错误的文本.
Java代码:
SimpleDateFormat df = new SimpleDateFormat("dd-MM-YYYY");
java.util.Date myDate;
myDate = df.parse(editText1.getText().toString());
String myText = myDate.getDay() + "-" + myDate.getMonth() + "-" + myDate.getYear() + "abcd";
Run Code Online (Sandbox Code Playgroud)
XML代码:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date">
Run Code Online (Sandbox Code Playgroud)
当我在EditText中写入文本"23-08-2013"时,代码返回"5-7-113-abcd".怎么了?如何从EditText获取正确的日期?