如何将日期格式 12/20/2014 更改为 2014 年 12 月 20 日,如果您能告诉我 android 中的 mm/dd/yyyy 是否未知。
嗨,下面的代码工作正常。.
public static String setChangeDateFormat(String dateStr) {
String inputPattern = "yyyy-MM-dd";
String outputPattern = "MMMM dd, yyyy";
SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);
Date date = null;
String startDate = null;
try {
date = inputFormat.parse(dateStr);
startDate = outputFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return startDate;
}
月份表示
如下:-
Jan = 0, dec = 11
并且您通过 12,因此默认情况下显示 1 月。见以下示例:-
http://www.mkyong.com/java/java-date-and-calendar-examples/
阅读本文档以获取更多信息:-
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html