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









Related Tutorials/Questions & Answers:
How to get of lastmodified file list between two times in java?
difference between java5 and java6 - Java Beginners
Advertisements
how to get string between two characters
To get the String between two strings
list of all months between two dates in java
list of all months between two dates in java
Javah -  Header File Generator
How to manage cookie in between two JSP Pages
Java2
How to find out the friend user between two columns in sql database
How to select Data Between Two dates in Java, MySQL
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
How to list even numbers between 1 and 100?
about java1
mysql difference between two numbers
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
Javah
Artifacts of javax
How can we know the number of days between two given dates using PHP?
calculate difference between two time in jsp
Drag and Drop between two list control in Flex4
Listing all even numbers between two numbers
Java get File List
how to get description for each file
how to seperation one file into two - Java Interview Questions
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours
About Java2
How to read text file to two different name array
How to read text file to two different name array
java collision detection between two images
Collision Detection between two images in Java
Compare two word file
Javascript calculate number of days between two dates
How to store two integer value in a separate file and retrieve those values
how to get file extension in java
days between two given dates using PHP
How to get path of a file in iOS?
how to add two object in a particular file - Java Beginners
javaa swings - IDE Questions
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala
Java get number of days between dates

Ads