• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: How to solve "48 hours" ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic