Java 从jsf页面读取两个日期,并使用

Java 从jsf页面读取两个日期,并使用,java,file,timestamp,Java,File,Timestamp,我有以unix时间戳结尾的文件,例如: Product.txt.1500256801 Product.txt.1500260400 Product.txt.1500264001 Product.txt.1500267601 ... 在5天内,这些文件将增加到120个文件 对于exm:我想搜索文件中的任何单词,但不是所有的5天,而是3天 从2017年7月5日起 至2017-07-08 这两个日期和我搜索的单词由jsf页面输入 问题不在于jsf页面或如何在文件中查找word 真正的问题是,当我从日

我有以unix时间戳结尾的文件,例如:

Product.txt.1500256801
Product.txt.1500260400
Product.txt.1500264001
Product.txt.1500267601
...
在5天内,这些文件将增加到120个文件 对于exm:我想搜索文件中的任何单词,但不是所有的5天,而是3天 从2017年7月5日起 至2017-07-08 这两个日期和我搜索的单词由jsf页面输入 问题不在于jsf页面或如何在文件中查找word 真正的问题是,当我从日期开始搜索
toDate
时,我是如何在该日期限制搜索的(为了确认:在这3天内,我将有72个文件,我想搜索72个文件,而不是全部124个文件)

我尝试过这个想法: 将所有时间戳读取到字符串列表

for(int i=0; i<listOfExt; i++)
{
stringList = listOfExt.get(i).replaceAll(regex,"$1");
}
lista1.add(stringList);//where. I get only from files name the suffix 1500256801,1500260400, and so on ...

我会使用新的日期/时间API,因为旧类(
Date
Calendar
SimpleDateFormat
)有和,它们正在被新的API所取代

如果您使用的是java8,那么就有一个在JDK中本机提供的


如果您使用的是Java,我在这里看不到任何jsf……如果您知道问题出在jsf页面及其控制器上,为什么不向我们展示这些页面的代码呢?尝试创建一个问题的解决方案。请注意,问题不是来自jsf页面,因为我成功地实现了这一点。在我的托管bean中,我收到了两个没有问题的日期,直到我可以将它们转换为时间戳,我想在没有jsf页面的情况下解决问题。您好@Hugo,这就是搜索的目的,感谢您的解释和伟大的解决方案!
if(lista1.contains(fromDate)&&lista1.contains(toDate))
{
lista2 = lista1.subList(lista1.indexOf(startDate),lista1.indexOf(endDate)+1);
lista3.add(lista2.toString);
}
else
{
//some thing such: the user entered date not created its file to now
}
// start date (set the time to start of day)
ZonedDateTime from = LocalDate.parse("2017-07-05").atStartOfDay(ZoneOffset.UTC);
// end date (set the time to 11 PM)
ZonedDateTime to = LocalDate.parse("2017-07-08").atTime(23, 0).atZone(ZoneOffset.UTC);
// parse date in day/month/year format
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy");
ZonedDateTime from = LocalDate.parse("05/07/2017", fmt).atStartOfDay(ZoneOffset.UTC);
// get start and end timestamps
long start = from.toInstant().truncatedTo(ChronoUnit.MINUTES).toEpochMilli() / 1000;
long end = to.toInstant().truncatedTo(ChronoUnit.MINUTES).toEpochMilli() / 1000;
// open directory that contains the files
File dir = new File("/your/folder/name");

// get the files with the timestamps between start and end
File[] files = dir.listFiles(new FilenameFilter() {

    @Override
    public boolean accept(File dir, String name) {
        // extract number from file name
        if (name.startsWith("Product.txt.")) {
            // divide by 10 to eliminate extra second (value is rounded as it's an int)
            // then multiply by 10 again to get timestamp of respective hour
            int timestamp = (Integer.parseInt(name.replace("Product.txt.", "")) / 10) * 10;
            System.out.println(timestamp);
            return start <= timestamp && timestamp <= end;
        }

        return false;
    }
});
// timezone
ZoneId zone = ZoneId.of("Asia/Baghdad");