Java I/O How to - Get last modified time in milliseconds since midnight on 1st January 1970 GMT








Question

We would like to know how to get last modified time in milliseconds since midnight on 1st January 1970 GMT.

Answer

import java.io.File;
import java.util.Date;
public class MainClass {
  public static void main(String[] args) {
    // Create an object that is a directory
    File myDir = new File("C:/Java_Dev");
    System.out.println(new Date(myDir.lastModified()));
  }
}

The code above generates the following result.