Warning : The code is broken due to the forum html bug with some characters
Hi&welcome,
Well to get started that's not an easy task
Mainly because your date are stored as strings.
You can use the java
Calendar class to use the getTime() method in order to compare two Dates. Like it's shown in this
example . You may have to add some additional import statements to let processing know which java classes you are dealing with. Like :
- import java.util.Calendar;
To set a date in Calendar you can use the method set() with following
arguments (or a more precise version if you need time too).
The main difficulty would be to extract the relevant values from your string and put them in the set method (after converted them to
int ). You can use regular expressions to do such strings manipulations. Processing allow reg exp trough the use of
match() .
If your strings are all the same syntax i've tried to extract day, month and year using a reg exp and that gives :
String date = "Tue, 28 Jun 2009 17:24:09 -0500";
String[] req;
/**
* (d{1,2}) means match at least one but not more than two digit characters -> day of the month
* s means drop away the white space character
* (w{3}) means match exactly three word character -> month formatted as mmm
* s means as above
* (d{4}) means match exactly 4 digit characters -> year formmated as yyyy
*/
req = match(date, "(d{1,2})s(w{3})s(d{4})");
for (int i=0; i<req.length; i ++) {
println(req[i]);
} I didn't made any check and supposed that your month would always be formatted as 3 characters (Jan, Feb..) and that your Years would be formatted as 4 characters (2011..)
Then you can access to each elements with :
- day, req[1]
- month, req[2] (need to be converted to a number between 0-12 before use it with calendar)
- year, req[3]
So basically, you need to do that for two dates, creating calendar object containing your date extracted.
And then use the code snippet provided in the javakode link to get the day difference.
EDIT : Seems the the forum backslash bug is annoying when trying to using regular expression as it drop double-backslash even using html entity. Any workaround ?
\