We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › [Newbie] Date calculations
Page Index Toggle Pages: 1
[Newbie] Date calculations (Read 533 times)
[Newbie] Date calculations
May 15th, 2006, 5:21pm
 
Hello,

I have a very easy calculation to do : how can we know how many days there are between two dates ?

We get these dates from a webpage, in a string parameter "dd/mm/yyyy", and need to use them as coordinates. For the moment I do the calculation in my web page, and send directly the coordinate, but it would be much cleaner to do all these things in the applet.

Do "date" classes exist in Processing for this purpose ?

Thanks for you help.
Re: [Newbie] Date calculations
Reply #1 - May 16th, 2006, 4:49pm
 
you should use the java date class, which will let you do all those things:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html
Re: [Newbie] Date calculations
Reply #2 - May 17th, 2006, 9:42am
 
Thanks a lot, this allows to do everything one could want.
Re: [Newbie] Date calculations
Reply #3 - May 17th, 2006, 11:00am
 
heh, i did this function just last week


// get number of days between two dates
int getDaysBetween (Date d1, Date d2) {
   int msPerDay = 1000 * 60 * 60* 24;
   long firstTime =d1.getTime();
   long lastTime = d2.getTime();
   int difference = floor(lastTime/msPerDay) -  floor( firstTime/msPerDay);
   return difference;
}
Page Index Toggle Pages: 1