How can I convert a file.lastModified() long value to a date time value?

7
I have a Java action where I get a long value from the file.lastModified() method. I.E.: 1251207195886, this is a file from 25-08-2009 (shown in windows) Now I want to convert this long value to a dd-MM-yyyy hh-MM-ss notation. How can I do this?
asked
1 answers
8

You can create a Date object with your long, where the long is the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT. Use the following code.

Date yourDate = new Date(yourLong);
DateFormat formatter =  new SimpleDateFormat("dd-MM-yyyy hh-MM-ss");
String formattedDate = formatter.format(yourDate);

Good luck.

answered