Java File Time Get getFileLastModified(File file)

Here you can find the source of getFileLastModified(File file)

Description

get File Last Modified

License

Open Source License

Parameter

Parameter Description
file a parameter

Return

the last modified date of the file with the default format : yyyy-MM-dd HH:mm:ss

Declaration

public static String getFileLastModified(File file) 

Method Source Code


//package com.java2s;

import java.io.File;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**// w ww .java2s  .c om
     * 
     * @param file
     * @return the last modified date of the file with the default format : yyyy-MM-dd HH:mm:ss
     */
    public static String getFileLastModified(File file) {
        return getFileLastModified(file, "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 
     * @param file
     * @param format
     *            the date format like "yyyy-MM-dd"
     * @return the last modified date of the file
     */
    public static String getFileLastModified(File file, String format) {
        Date date = new Date(file.lastModified());
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date).toString();
    }
}

Related

  1. getFileLastModified(File file)
  2. getFileTimestamp(long timeStampinMillis)