File last access time on Android

不想你离开。 提交于 2019-12-05 17:19:35
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            StructStat stat = null;
            try {
                stat = Os.stat("/sdcard/Pictures/abc.jpg"); // File path here
            } 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 works for only above Lollipop APIs though.

Also note that st_atime returns time in seconds and not in milliseconds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!