How to get the date and time of a file in Java

1 Answer

0 votes
package javaapplication1;

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

public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            File file = new File("d:\\data.txt");
 
            SimpleDateFormat simpledateformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
 
            System.out.println(simpledateformat.format(file.lastModified()));
        }
        catch (Exception e)
        {
            System.out.println(e.toString());
        }  
    }
}

/*

run:

12/31/1999 03:42:17

*/

 



answered Jun 19, 2015 by avibootz

Related questions

1 answer 196 views
1 answer 1,189 views
1,189 views asked Jun 19, 2015 by avibootz
1 answer 198 views
1 answer 146 views
1 answer 192 views
...