我试图使用Android的SimpleDateFormat是这样的:
I am trying to use the Android SimpledateFormat like this:
String _Date = "2010-09-29 08:45:22"
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = fmt.parse(_Date);
return fmt.format(date);
}
catch(ParseException pe) {
return "Date";
}
}
结果是好的,我有:2010-09-29
The result is good and i have: 2010-09-29
但是,如果我改变的SimpleDateFormat到
But if i change the SimpleDateFormat to
SimpleDateFormat("dd-MM-yyyy");
问题是,我会得到03-03-0035 !!!!
the problem is that I will got 03-03-0035 !!!!
为什么和如何得到像DD-MM-YYYY格式
Why and how to get the format like dd-MM-yyyy
我想你想扭转日期格式?
I assume you would like to reverse the date format?
的SimpleDateFormat可用于解析和格式化。 你只需要两种格式,一种解析字符串和其他返回所需的打印输出:
SimpleDateFormat can be used for parsing and formatting. You just need two formats, one that parses the string and the other that returns the desired print out:
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date date = fmt.parse(dateString);
SimpleDateFormat fmtOut = new SimpleDateFormat("dd-MM-yyyy");
return fmtOut.format(date);