且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.lang.IllegalArgumentException异常:解析错误​​ - 无法在Android的解析日期

更新时间:2023-01-24 13:15:59

看来你的日期格式是错误的。你应该注意的是大写 M 是用来重新present个月,小写 M 用于分钟。为了解决这个问题只需要改变你的 YYYY-MM-DD YYY-MM-DD

It seems your date format is wrong. You should take note that the uppercase M is used to represent months and the lowercase m is used for minutes. To solve this just change your yyyy-mm-dd to yyy-MM-dd.

现在,如果你想改变,在未来的格式,你可以做这样的事情这样做的:

Now if you want to change that format in the future you may do so by doing something like this :

try {
     DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     Date input = inputFormat.parse(date);
     DateFormat outputFormat = new SimpleDateFormat(" EEEE MMMM-dd-yyyy ", Locale.ENGLISH);
     String finaldate = outputFormat.format(input);
            txtDate.setText(finaldate); <-- just an example of displaying the date 
     }catch (Exception ex) {
            Alerts.CatchError(getBaseContext(), ex.toString());
     }

这将显示 2015年4月25日12时08分34秒(YYYY-MM-DD HH:MM:SS)的初始存储日期周五4月-25-2015 。您当然可以改变这种以自己的喜好为好,只是参考文档ANKIT欣然为你联系。

This will display the initially stored date of 2015-04-25 12:08:34 ( yyyy-MM-dd HH:mm:ss ) as Friday April-25-2015. You can of course change this to your liking as well, just refer to the documentation Ankit has kindly linked for you.