Created
October 26, 2019 18:22
-
-
Save EduardoSP6/774522b2826d52cb05d58665ca285be5 to your computer and use it in GitHub Desktop.
Get file's creation time - Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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