Reputation: 93
I have an requirement to calculate the time difference between Lastmodified Time of a file and currentTime of FTP sever on which the file is present.
A file named abc.txt (last modified - July 23 2014 1:00:00 AM ) is present in a US FTP Server. I need to get the last modified time stamp (t1) of the file & currentTime of the US FTP server(t2) and calculate the difference in minutes between the two times ( d1,d2 )
Here's what I have so far.
Calendar zonedate = Calendar.getInstance();
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("MST"));
System.out.println("PDT :: "+ formatter.format(zonedate.getTime()));
String d1 = formatter.format(zonedate.getTime());
System.out.println(d1);
Date d2 = formatter.parse(d1);
System.out.println(d2);
Upvotes: 0
Views: 768
Reputation: 307
You can try this :
Upvotes: 0
Reputation: 3811
use File.lastModified() to get last modified, System.currentTimeMillis() to get CurrentTime. Subtract them to get the diff in milliseconds.
diff_in_mins = diff_in_milli_seconds/1000/60;
Upvotes: 1