G
GaryM
Is there an easy way to perform day boundary comparisons?
I have a large directory of archived files and I want to zip them up
when they are older than 7 days. I can make it work using
System.currentTimeMillis() - (2 days in millis) versus the
file.lastModified() date. However, to get it at the day level I am
creating a GregorianCalendar and setting the time to 1ms after
midnight.
Was wondering if there was a simpler way to do this such that < and
<= would work at the day level? Do I need to make Date objects and
simply compare d/m/y elements?
Here is the code I have been using to get the base date for
comparison:
// Set the time to 00:00:00 + 1ms and -7 days
Calendar c = new GregorianCalendar();
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 1);
c.add(Calendar.DAY_OF_MONTH, -7);
long compareDate = c.getTimeInMillis();
Thanks in advance,
Gary
I have a large directory of archived files and I want to zip them up
when they are older than 7 days. I can make it work using
System.currentTimeMillis() - (2 days in millis) versus the
file.lastModified() date. However, to get it at the day level I am
creating a GregorianCalendar and setting the time to 1ms after
midnight.
Was wondering if there was a simpler way to do this such that < and
<= would work at the day level? Do I need to make Date objects and
simply compare d/m/y elements?
Here is the code I have been using to get the base date for
comparison:
// Set the time to 00:00:00 + 1ms and -7 days
Calendar c = new GregorianCalendar();
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 1);
c.add(Calendar.DAY_OF_MONTH, -7);
long compareDate = c.getTimeInMillis();
Thanks in advance,
Gary