Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compare 2 java.util.Dates

 
Kip Dekan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've got a simple problem please help me,
I have 2 java.util.Date() Objects
e.g.
date1 = 2003 Jul 01 12:45:36
date2 = 2003 Jul 01 09:08:59
now I'd like to compare the two dates without the Time Part
that means:
if(date1.compareTo(date2) = 0) should return 0
now the question how to compare only the DatePart of a java.util.Date?
Thanks for helping
[ July 03, 2003: Message edited by: Dekan ]
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dekan,
You can get the year, month, and date with getYear(), getMonth(), and getDate() from both Date object, then compare it. But since it's deprecated, you can use class GregorianCalendar instead. There is the method get(int field).
Susilo
 
Kip Dekan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
now it works
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dekan,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!