getDay()返回星期几,所以这是错误的.使用getDate().
getMonth()从零开始,因此您需要为其添加1.
getYear()返回一个值,该值是从年份中减去1900的结果,因此您需要向其中添加1900.
abcd – 好吧,你明确地将它添加到字符串的末尾所以没有惊喜:)
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
Date myDate;
try {
myDate = df.parse(date);
String myText = myDate.getDate() + "-" + (myDate.getMonth() + 1) + "-" + (1900 + myDate.getYear());
Log.i(TAG,myText);
} catch (ParseException e) {
e.printStackTrace();
}
所有这些都被弃用了,你应该真的使用日历.
编辑:日历的快速示例
Calendar cal = Calendar.getInstance();
cal.setTime(myDate);
cal.get(Calendar.DAY_OF_MONTH); // and so on