How to get the creation date of file in android. I know about file.lastModified(), but I really need the creation date, that you can see in OS Windows in Properties of file.
If someone know the solution of this task, please, write it below this message. Thanks!
Android's emulated filesystem does not store the creation date of files or folders, so there is no way to retrieve this data, as it does not exist. (Many thanks to Irfan Latif for confirming this, and to Izzy for clarifications.)
The easiest way to get the file creation date is with the stat command. As we can see, the creation date is shown in the “Birth” field.
Right-click the current time and select the option to "Adjust Date/Time." Choose the option to "Change Date and Time..." and input the new information in the time and date fields. Press "OK" to save your changes and then open the file you want to change.
The modified date of a file or folder represents the last time that file or folder was updated.
Creation dates are not supported by every operating system. That's why Java doesn't have a method to get the creation date of a file. I ran into this problem recently also.
What I did was append the timestamp as appendix for the file.
File f = new File("myFile-" + System.currentTimeMillis());
When you later look for your file, you'll be able to extract the appendix and convert it back to a date to find it's creation date.
String fileName = f.getName();
String[] split = fileName.split("-");
long timeStamp = 0;
try {
timeStamp = Long.parseLong(split[1]);
} catch(NumberFormatException nfe) {
nfe.printStackTrace();
}
System.out.println("Creation date for file " + f + " is " + new Date(timeStamp));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With