if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
StructStat stat = null;
try {
stat = Os.stat("/sdcard/Pictures/abc.jpg");
} catch (ErrnoException e) {
e.printStackTrace();
}
long t2 = stat.st_atime *1000L;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(t2);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh-MM-ss");
String formattedDate = formatter.format(calendar.getTime());}
This only works for the Lollipop API.
Also note that st_atime returns time in seconds, not milliseconds.
source
share