lastmodified date

public void choosefile() {

JFileChooser fc = new JFileChooser();

int result = fc.showOpenDialog(null);

if (result == JFileChooser.CANCEL_OPTION)

JOptionPane.showMessageDialog(null, "Operation cancelled");

else {

File filename = fc.getSelectedFile();

String s = "Name: " + filename.getName() + "\n" +

"Path: " + filename.getPath() + "\n" +

"Parent:" + filename.getParent() + "\n" +

"Length:" + filename.length() + "\n" +

"Can Read: " + filename.canRead()+ "\n" +

"Can Write: " + filename.canWrite() + "\n" +

"Last Modified: " + filename.lastModified();

txtArea.setText(s);

}

}

Above are my methods for choosing the file and thenon displaying its various properties

Below are my results:

Name: xuweiliangvictor.jpg

Path: D:\xuweiliangvictor.jpg

Parent:D:\

Length:12512

Can Read: true

Can Write: true

Last Modified: 1177514242366

May I know how could I display the last modified date as : DayofWeek Month Day Time Zone Year?

Like Thu Apr 10 12:17:04 SGT 2003

Many many thanks in advance :)

[1169 byte] By [victorxua] at [2007-11-27 4:36:02]
# 1
> May I know how could I display the last modified date> as : DayofWeek Month Day Time Zone Year?> > Like Thu Apr 10 12:17:04 SGT 2003> > > Many many thanks in advance :)Take a look at SimpleDateFormatKaj
kajbja at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 2

As the API states, lastModified returns:

<quote>

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.

</quote>

Construct a java.util.Date out of that and format the date and time as you like using a java.text.SimpleDateFormat. See the API for details.

Hippolytea at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 3
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
kajbja at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 4
Many thanks guys!Do appreciate the kind gestures mates! :)
victorxua at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 5

Use the class SimpleDateFormat:

http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html

Basically, you need something like:

String date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(new Date(dateAsALong));

Dalzhima at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 6
> Many thanks guys!> Do appreciate the kind gestures mates! :)Np
kajbja at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks alot too Dalzhim !
victorxua at 2007-7-12 9:46:11 > top of Java-index,Java Essentials,Java Programming...