java中如何比较两个日期?
我正在尝试比较两个日期,我只想比较日期部分而不是时间部分,这就是我在程序中存储日期的方式:
Thu Jan 27 23:20:00 GMT 2011
我有一个:
ArrayList<Date> dateList;
并且我想使用
dateList.compares(newDate);
// if the answer was false which means I
// have new date then add the newdate to my list
,但由于时间部分也涉及我无法得到正确的答案。 我该如何解决我的问题?
我不想使用 JODA-TIME
I'm trying to compare two dates together and I only want to compare the date part not the time part this is how I store date inside my program :
Thu Jan 27 23:20:00 GMT 2011
I have an:
ArrayList<Date> dateList;
and I want to use
dateList.compares(newDate);
// if the answer was false which means I
// have new date then add the newdate to my list
but since the time part also is involved I can't get the proper answer.
How can I fix my problem?
I don't want use JODA-TIME
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以像这样逐个比较值
或者
如果您使用 Date 类,请考虑使用 Calendar 类
这是最优雅的解决方案,使用日历和比较器来实现此
用法:
You can compare value by value like this
Or
If you work with Date class, consider using Calendar class instead
Here's the most elegant solution, using Calendar and Comparator for this
Usage:
为什么不使用compareTo()?
Why dont you use compareTo()?
您可以使用此
编辑:
Joda 时间或否此帖子包含日期比较的所有答案
如何比较两个没有时间部分的日期?
You can use this
EDIT:
Joda time or no this SO post has all answers for date comparison
How to compare two Dates without the time portion?