Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert the file last modified timestamp to a date?

Tags:

java

date

How do I convert File#lastModified() to a real date? The format is not really important.

like image 416
London Avatar asked Apr 02 '11 21:04

London


People also ask

How do I convert a timestamp to a date?

You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.

How do I change date modified to date?

Right-click on the toolbar and select "customize". Then go to File 1 -> and check the "RAHS attributes/timestamp" box and push OK. You'll now have that "RAHS" button on the toolbar. You can then select the folder where the files are that you've rotated and which have thus had their "date modified" values changed.

How do I change the last modified date in Word?

To change the creation date on Word document settings, select the "File Properties" tab and check the box next to Modify File Date and Time Stamps. The dates are located below, and you can manually change the creation date and, if desired, the date and times of edits and modifications.

How do you change the last modified date in Excel?

If you want to change the last modified date or change the file creation data, press to enable the Modify date and time stamps checkbox. This will enable you to change the created, modified, and accessed timestamps—change these using the options provided.


2 Answers

Date d = new Date(file.lastModified()); 

lastModified() returns the milliseconds since 1970-01-01, and the Date class stores its time also in the same way. The Date(long) constructor takes these milliseconds, and initializes the Date with it.

like image 69
Daniel Avatar answered Oct 06 '22 12:10

Daniel


Just you use the SimpleDateFormat class to convert long to date. Only you execute code:

new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(     new Date(new File(filename).lastModified())  ); 
like image 20
Shankar Kumar Thakur Avatar answered Oct 06 '22 10:10

Shankar Kumar Thakur