File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time Stamp for an external file

 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way that I can get a timestamp from a given file at a specified path. For example, how can I get a time stamp from
C:\myRoot\myTextFile.txt
and have it print out
04/11/2001 01:00:00
or something close so that we know its a time and date.
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
Vinod Mehta
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import java.util.*;
public class test {
public static void main (String args []) {
File f = new File ("C:\\Autoexec.bat");
System.out.println(f.lastModified());
Calendar c = Calendar.getInstance();
c.setTime(new Date(f.lastModified()));
String szTime = "Last Modified on " + c.get(Calendar.MONTH) + "/" + c.get(Calendar.DATE) + "/" + c.get(Calendar.YEAR) +
" At " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + ":" + c.get(Calendar.MILLISECOND) + c.get(Calendar.AM_PM);
System.out.println (szTime);
}
}
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help! PERFECT!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic