Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NX: How to solve "48 hours" ?

 
yanjun wang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my instructions,there is : " They take bookings only within 48 hours of the start of room occupancy. ".
I try to compare the system date and the record date. I have make them Date
Object by "today = new Date();" and "formatter = new SimpleDateFormat("yyyy/MM/dd", currentLocale);".
But when I try "int number = today.compareTo(testDay); ",the result is "number = 1" when
today is after testDay.
What I want to get is the concrete days between the two date.
eg: 2004/02/09 - 2004/02/02 = 7(days). now 48 hours is two days long.
How to get this? or any other solution?
Appreciate for your comments....
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compareTo never claimed that it returns the difference, only that it returns a positive number, 0, or negative number for greater, equal, or less than.
To compare dates, convert them to their millisecond representation (e.g. date.getTime()), then subtract one from the other. Now you have the difference in milliseconds. There are a fixed number of milliseconds in a day (1000 * 60 * 60 * 24), so you should be able to calculate that.
 
Xie Ruchang
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yanjun,
I got the UrlyBird and I read from other threads that you can side step this requirement of 48 hours to a business requirement rather a system requirement. In another words, you may consider not implementing the validation and putting your justification in Choices.txt.
Just for your information. I did that.
Best Regards
 
yanjun wang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billybob Marshall ,thank you very much! I have implemented in your way. It"s OK!
Frankie Cha ,thank you for your very nice comments,I will document it in Choices.txt.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!