How to get of lastmodified file list between two times in java?

How to get of lastmodified file list between two times in java?

Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two times like get the last modified file bet 02:00:00am and 01:00:00am (so the interval time is 23h)

import java.io.*;
import java.text.*;
import java.util.*;

public class FileFilterDateIntervalUtils implements FilenameFilter {
    String dateStart;
    String dateEnd;
    SimpleDateFormat sdf;

public FileFilterDateIntervalUtils(String dateStart, String dateEnd) {
    this.dateStart = dateStart;
    this.dateEnd = dateEnd;
    sdf = new SimpleDateFormat("yyyy-MM-dd");
}

public boolean accept(File dir, String name) {
    Date d = new Date(new File(dir, name).lastModified());
    String current = sdf.format(d);
    return ((dateStart.compareTo(current) < 0
            && (dateEnd.compareTo(current) >= 0)));
}

}

// then this

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileSortDateInterval {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        FileFilterDateIntervalUtils filter =
            new FileFilterDateIntervalUtils("2010-01-04", "2011-01-20");
        File folder =  new File("G:/Temp");
        File files[] = folder.listFiles(filter);
        for (File f : files) {
            System.out.println(f.getName() + " "
                    + sdf.format(new Date(f.lastModified())));
        }
    }
}

Google gave me these codes Thank you

View Answers

January 21, 2011 at 12:36 PM

Hi Friend,

Check this:

import java.io.*;
import java.text.*;
import java.util.*;

 class FileFilterDateIntervalUtils implements FilenameFilter { 
     String dateStart;
     String dateEnd;
     SimpleDateFormat sdf;

public FileFilterDateIntervalUtils(String dateStart, String dateEnd) {
    this.dateStart = dateStart;
    this.dateEnd = dateEnd;
    sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
}

public boolean accept(File dir, String name) {
    Date d = new Date(new File(dir, name).lastModified());
    String current = sdf.format(d);
    return ((dateStart.compareTo(current) < 0
            && (dateEnd.compareTo(current) >= 0)));
}

} 
public class FileSortDateInterval {
    public static void main(String[] args) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
    FileFilterDateIntervalUtils filter = new FileFilterDateIntervalUtils("2010-11-20 11:30:00 AM", "2010-11-30 11:15:00 AM");
    File folder = new File("C:/roseindia");
    File files[] = folder.listFiles(filter);
    for (File f : files) {
        System.out.println(f.getName() + " " + sdf.format(new Date(f.lastModified())));
        }
 } 
}

Hope that it will be helpful for you.

Thanks


January 21, 2011 at 5:45 PM

H , thank you very much for youe help.

it works

Ads









Related Tutorials/Questions & Answers:
How to get of lastmodified file list between two times in java?
how to get string between two characters
Advertisements
list of all months between two dates in java
list of all months between two dates in java
How to manage cookie in between two JSP Pages
Javah -  Header File Generator
How to find out the friend user between two columns in sql database
How to select Data Between Two dates in Java, MySQL
how to get description for each file
how can i draw line between two panel contaning circle and line between their center?
how to create directed line between two buttons when i clicked there
Java2
How to list even numbers between 1 and 100?
how to get file extension in java
How to get path of a file in iOS?
mysql difference between two numbers
Artifacts of javax
calculate difference between two dates
Write a program to list all even numbers between two numbers
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours
calculate difference between two time in jsp
Listing all even numbers between two numbers
Javah
How to get a list of all indexes in python-elasticsearch
How to read text file to two different name array
How to read text file to two different name array
How to get a list of MySQL user accounts?
How to get a list of MySQL user accounts?
Java get File List

Ads