SimpleDateFormat 解析的日期超出了应有的范围?
我这里有一个 arrayList
list.add(new Release(nameString, platform, genre, releaseDate, urlString));
setAlerts();
这是我用来获取列表大小并解析日期的方法。
for(int i=0;i<list.size();i++){
Release eDate = new Release(nameString, platform, genre, releaseDate, urlString);
String reDate = eDate.getReleaseDate();
String nameOf = eDate.getName();
if(reDate.contains(",")){
Date dateParsed = null;
try {
dateParsed = new SimpleDateFormat("MMMM dd,yyyy").parse(reDate);
} catch (ParseException e) {
e.printStackTrace();
}
String dateFormated = new SimpleDateFormat("dd-MM-yyyy").format(dateParsed);
}
}
此方法多次解析相同的日期。列表中只有 13 个项目,但它解析的项目要多得多。
无论如何我可以改变方法来纠正这个问题吗?
它还仅返回列表中最后几个项目的日期。不是全部。
I have an arrayList here
list.add(new Release(nameString, platform, genre, releaseDate, urlString));
setAlerts();
Here is the method i am using to get the size of the list and parse the dates.
for(int i=0;i<list.size();i++){
Release eDate = new Release(nameString, platform, genre, releaseDate, urlString);
String reDate = eDate.getReleaseDate();
String nameOf = eDate.getName();
if(reDate.contains(",")){
Date dateParsed = null;
try {
dateParsed = new SimpleDateFormat("MMMM dd,yyyy").parse(reDate);
} catch (ParseException e) {
e.printStackTrace();
}
String dateFormated = new SimpleDateFormat("dd-MM-yyyy").format(dateParsed);
}
}
This method parses the same date more than once.. it is only 13 items in the list, and it parses WAY more.
Is it anyway i can change the method to correct this?
It also only returning the dates for the last couple of items in the list. not all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您循环遍历一个列表,因此如果您的列表实际上只包含 13 个元素,则您将多次调用该方法(在每个
list.add(..)
之后?)此外,您正在循环遍历一个列表,但是您没有对列表本身执行任何操作..您不需要从列表中检索元素并对它们执行某些操作(
Release release = (Release) list.get(i)
) ..不然你为什么要循环一个 列表?您是否尝试过调试您的应用程序?
You loop over a list, so if your list really contains only 13 elements, you are calling the method multiple times (after each
list.add(..)
?)Also, you are looping over a list, but you are not doing anything with the list itself .. don't you need to retrieve the elements from your list and do something with them (
Release release = (Release) list.get(i)
) .. why else would you loop over a list?Have you tried debugging your app?