【问题标题】:Java Code : How do I select files from a directory based on their date modified which should be equal to the date specified in the stringJava代码:如何根据修改日期从目录中选择文件,修改日期应等于字符串中指定的日期
【发布时间】:2016-07-03 06:26:46
【问题描述】:

我在字符串“03/09/16”中有一个日期值。如何根据修改日期从目录中选择文件,该日期应等于字符串中指定的日期。

我的要求是只选择“修改日期”=“字符串中指定日期”的文件。

【问题讨论】:

  • 文件系统依赖于操作系统,您是否接受仅适用于一个操作系统的解决方案?

标签: java string file date last-modified


【解决方案1】:

对于您的情况:

File file = new File("C:\\Temp\\filenmae.type");
Date modifiedDate = new Date(file.lastModified());
Calendar modifiedCal = Calendar.getInstance();
modifiedCal.setTime(modifiedDate);
Calendar cal = (Calendar) modifiedCal.clone();
cal.set(Calendar.YEAR, 2016);
cal.set(Calendar.MONTH, 2); // Start from 0
cal.set(Calendar.DAY_OF_MONTH, 9);      
if (modifiedCal.compareTo(cal) == 0) {
    System.out.println("Same date!!!"); 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    相关资源
    最近更新 更多