Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

problem with date calcaulation

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi... i'm using the code below to find out the difference between the 2 date and time...
Date fr = new java.util.Date();
Date to1= new java.util.Date();
long time1 =0;
long time2 =0;
String from = "2004-03-25 09:07:05";
String to = "2004-04-01 14:54:01";
from = sdf123.parse(f);
to = sdf123.parse(t);
time1 = from.getTime();
time2 = to.getTime();
long result = (time2-time1)/(24 * 60 * 60 * 1000); // gives the diff in days
Now the output for the result is '-23' where as the output should be 7 days
BUT when the value for the string '
from is ="2004-04-01 14:54:01" ' and
to ="2004-04-05 10:20:01"
....at that time i get the correct output i.e 5 days..!!!
y is to so ..??? plz help me to get the correct difference in days...plz help...!!!
plz help....
thanxs..!
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do a search for "GregorianCalendar" or just "Calendar" and you'll find what you need.
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic