How to get file last modified date in java

In this post you will learn how to get file last modified date in java.

how to get file last modified date in java

In java file last modified can be determined using Java.io.File.lastModified() method. This method return time in milliseconds. You can format it to human readable format using SimpleDateFormat.

Also read – date time java program

Let’s see how to get the file last modified date in java,

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

public class LastModifiedDateDemo
{
   public static void main(String[] args)
   {
      File file = new File("d:\\modifiedFile.txt");
      System.out.println("Before file format : " + file.lastModified());
      SimpleDateFormat sim = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
      System.out.println("After file format : " + sim.format(file.lastModified()));
   }
}

Output:

Before file format : 1486480590836
After file format : 02/07/2014 05:14:10

Related Posts