This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check whether Dates are equal? .  RSS feed

 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have got a queer problem. For a Swing screen I have got 3 Date fields.
1. Proposal Date (dd/mm/yy).
2. Forward Date (dd/mm/yy).
3. Communication Date (dd/mm/yy).
The problem arises when front screen validations are
performed.
For eg, after all the textfields in the GUI Screen are
filled and if all the dates in all the above 3 fields are
same, an error msg should pop up saying "All the 3 dates
are equal".
I will explain the validation process.
I create 3 Date Objects with constructors having
corresponding year,month and date values. Using
setDate,setMonth and setYear the Date Object is intialised
to the new values.
Using compareTo()I check for the equality of Date
Objects. Since all 3 Date Objects have the same dd/mm/yy, I
naturally expected the int value of compareTo()to be 0.
But that was not the case to be. Instead I found that 2nd
and 3rd Date Objects were equal. The 1st Date was not equal
with 2nd nor 3rd.
On closer examination,I found that getTime() of 1st Date
Object was different from 2nd and 3rd Date Object(which was
same).
I then used the setTime() to set the 2nd Date object time
value to the 1st Date Object. Even though my problem was
solved,it was shortlived. After the error msg is popped
up,even after I change the dates the same msg is being
displayed.
Is there any other way to make the creation time uniform
for all Date objects so that when I use getTime(),all Date
Objects return the same value?.
with warm regards,
Arun.




 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use SimpleDateFormat to create the Date Object.

Since you don't provide the Time portion of Date, it gets set to 00:00:000

------------------
Hope This Helps
Carl Trusiak, SCJP2
 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carl,
Your code was too complex for me to understand. Could you please make it more simpler for me to understand?.

with warm regards,
Arun.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!