Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

NX: How to solve "48 hours" ?

 
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....
 
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.
 
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.
 
You can't have everything. Where would you put it?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic