Skip to content

Instantly share code, notes, and snippets.

@EduardoSP6
Created October 26, 2019 18:22
Show Gist options
  • Save EduardoSP6/774522b2826d52cb05d58665ca285be5 to your computer and use it in GitHub Desktop.
Save EduardoSP6/774522b2826d52cb05d58665ca285be5 to your computer and use it in GitHub Desktop.
Get file's creation time - Android
public static Date getFileCreationDate(File file) {
Date createdAt = new Date();
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
createdAt = new Date(file.lastModified());
} else {
BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
createdAt = new Date(attr.creationTime().toMillis());
}
} catch (IOException e) {
e.printStackTrace();
}
return createdAt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment