在Java中,可以使用File.lastModified()来获取文件的最后修改的时间戳。 此方法将返回以毫秒为单位的时间(长值),您可以使用SimpleDateFormat对其进行格式化,以使其成为人类可读的格式。
文件上次修改
package com.mkyong.file;
import java.io.File;
import java.text.SimpleDateFormat;
public class GetFileLastModifiedExample
{
public static void main(String[] args)
{
File file = new File("c:\\logfile.log");
System.out.println("Before Format : " + file.lastModified());
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
System.out.println("After Format : " + sdf.format(file.lastModified()));
}
}
结果
Before Format : 1275265349422
After Format : 05/31/2010 08:22:29
翻译自: https://mkyong.com/java/how-to-get-the-file-last-modified-date-in-java/