I had the opportunity to write a program that detects files older than ○ days in Java, so I'll leave it as a reminder. As an example only.
Date is also possible, but try using a newer Local Date.
Long lastModified = targetFile.lastModified();
LocalDate lastDate = Instant.ofEpochMilli(lastModified).atZone(ZoneId.systemDefault()).toLocalDate();
This gets the last modified date from the target file declared in the file class. Image of converting epoch time to LocalDate type.
LocalDate daysBefore = LocalDate.now().minusDays(5);
Get today's date with now () of LocalDate class. This time, the date 5 days ago is targeted, and it can be obtained with minusDays (5).
if (lastModified.isBefore(base) || lastModified.isEqual(base))
if (lastModified.compareTo(base) <= 0)
if (lastModified.until(LocalDate.now(), ChronoUnit.DAYS) >= 5)
After that, if you write an if statement like this, you should be able to burn files before the specified date. Please note that isBefore () alone can only be taken more than 5 days ago. I'll try to get it 5 days ago with isEqual ().
Postscript Comments from @swordone The conditional expression of the if statement was added.
It would be nice to pop the File class here. If you have any suggestions, please comment.
Recommended Posts