views:

332

answers:

5
    long lastmodify   =   f.lastModified();
    System.out.println("File Lost Modify:"+lastmodify);

I am running the above code of file("f"), but it displays the last modified time is:1267082998588 I am confusing, is this is time or not.? Actually what it is?

A: 

It's the number of milliseconds since the Unix epoch.

Try:

import java.text.*;
import java.util.*;
System.out.println(new SimpleDateFormat().format(new Date(f.lastModified())));

You can do whatever you want with the Date. See Date, SimpleDateFormat, and GregorianCalendar in particular.

Matthew Flaschen
A: 

That is the date [represented in milliseconds] that the file was edited. It is the amount of milliseconds that have passed since January 1st, 1970 [also known as the Unix Epoch]

ItzWarty
+5  A: 

Take a look at the File documentation. It returns the miliseconds since 00:00:00 GMT, January 1, 1970.

You can do this instead

long lastmodify = f.lastModified();
Date modified = new Date(lastmodify);
System.out.println("File Lost Modify:"+ modified);
Lombo
+1  A: 

Have a look at Javadoc of the method in the File class (it is clear enough):

public long lastModified()

Returns the time that the file denoted by this abstract pathname was last modified.

Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs

sateesh
+1  A: 
    long lastmodify   =   f.lastModified();
    Date dt=new Date();
    SimpleDateFormat date   = new SimpleDateFormat("dd/MM/yyyy");
    String modify=date.format(lastmodify);

This is also one of the answer i got..

Venkats