java.lang.IllegalArgumentException异常,在Android中使用日期格式 [英] java.lang.IllegalArgumentException in Android with DateFormat

查看:143
本文介绍了java.lang.IllegalArgumentException异常,在Android中使用日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code片段

Here is my code fragment

在这里日期在10月 - 2013 9时53分37秒的格式

here date in 10-Sep-2013 09:53:37 format

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());

请帮我理清这issue.here是我的错误。

Please help me to sort out this issue.here is my error.

尊敬的Piyush,

下面是放出来的时候,我用你的code

Here is out put when i used your code

推荐答案

创建一个方法,如下面

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 "";
    }

然后把它作为

And then call it as

tvDate.setText(formatDate(salesReportItems.getDate().toString()));


了解更多关于我如何可以更改日期格式java的

这篇关于java.lang.IllegalArgumentException异常,在Android中使用日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆