check if a date is before 01-01-1970
in
Programming Questions
•
2 years ago
So basicly if it's before 1970 since there are no days in 1970 before 01-01-1970.
I found javadocs very confusing, i can't even find the .getTime(); function i used.
So i wonder, does DateFormat provide such thing?
I found javadocs very confusing, i can't even find the .getTime(); function i used.
So i wonder, does DateFormat provide such thing?
- //08-07-2010 01-01-2011
//11-01-1969 01-03-1970
String firstDateStamp;
String lastDateStamp;
void setup() {
firstDateStamp = "08-07-2010";
lastDateStamp = "01-01-2011";
print(calculateDaysInBetween(firstDateStamp, lastDateStamp));
}
int calculateDaysInBetween(String date1, String date2) {
long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
DateFormat stampFormat = new SimpleDateFormat("dd-MM-yyyy");
try {
Date firstDate = stampFormat.parse(date1);
long firstDateMillis = firstDate.getTime();
Date lastDate = stampFormat.parse(date2);
long lastDateMillis = lastDate.getTime();
int days = int((lastDateMillis - firstDateMillis)/MILLIS_PER_DAY);
return days;
} catch (ParseException e) {
die("Problem with dates", e);
}
return -1;
}
1