这是我的代码 fragment
这里的日期格式为 10-Sep-2013 09:53:37
TextView tvDate = (TextView) convertView.findViewById(R.id.entered_date);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
tvDate.setText(dateFormat.format(salesReportItems.getDate().toString()));
TextView tvCardType = (TextView) convertView.findViewById(R.id.card_type);
tvCardType.setText(salesReportItems.getCardType().toString());
请帮我解决这个问题。这是我的错误。
亲爱的Piyush,
这是我使用你的代码时的输出
最佳答案
创建如下所示的方法
private String formatDate(String dateString) {
try {
SimpleDateFormat sd = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss" /* 10-Sep-2013 09:53:37*/);
Date d = sd.parse(dateString);
sd = new SimpleDateFormat("yyyy-MM-dd");
return sd.format(d);
} catch (ParseException e) {
}
return "";
}
然后将其称为
tvDate.setText(formatDate(salesReportItems.getDate().toString()));
<小时/>
关于Android 中使用 DateFormat 的 java.lang.IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18733306/