我正在尝试使用 SimpleDateFormat 将我的月份转换为 MMM 格式,但无法转换。
tvDisplayDate = (TextView) findViewById(R.id.dateDisplay);
Calendar cal=Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MMM");
int tempyear = cal.get(Calendar.YEAR);
int tempmonth = cal.get(Calendar.MONTH);
int tempday = cal.get(Calendar.DAY_OF_MONTH);
String month = new Integer(tempmonth).toString();
最佳答案
以下作品(我刚刚测试过)
Calendar cal=Calendar.getInstance();
int tempmonth = cal.get(Calendar.MONTH);
SimpleDateFormat newformat = new SimpleDateFormat("MMM");
SimpleDateFormat oldformat = new SimpleDateFormat("MM");
String monthName = null;
Date myDate;
try {
myDate = oldformat.parse(String.valueOf(tempmonth));
monthName = newformat.format(myDate);
} catch (ParseException e) {
e.printStackTrace();
}
Log.d("MMM", monthName);
关于android - 将月份转换为 MMM 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11702334/