Reputation: 27
How can I create a folder or file with the current date and time and in a specific directory?
DateTimeFormatter f = DateTimeFormatter.ofPattern("uuuuMMdd HHmmss") ;
LocalDateTime ldtFile = LocalDateTime.parse(fileName, f) ;
ZoneId z = ZoneId.of("Asia/Tokyo") ;
ZonedDateTime zdtNow = ZonedDateTime.now(z) ;
LocalDateTime ldtThreeDaysAgo = zdtNow.minusDays(3).toLocalDateTime() ;
if(ldtFile.isAfter(ldtThreeDaysAgo))
{
....
}
I tried this example but it didn’t work for me as it is for Java 8+.
Upvotes: 2
Views: 103
Reputation: 158
try it:
public static String ArchiveDir;
Calendar calendar = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMdd HHmmss");
File sdPath = new File(AppPathData() + "/Archive/" + sdf.format(calendar.getTime()));
sdPath.mkdirs();
ArchiveDir = sdPath.getAbsolutePath();
return ArchiveDir;
Upvotes: 2