Copy link to clipboard
Copied
How to get file's last modified date with script?
Sure
alert(myFile.modified.getTime());
Copy link to clipboard
Copied
File object has a specific property modified, that you want to look at.
var myFile = File('pathToFile.js');
alert(myFile.modified);
Copy link to clipboard
Copied
great! it works! but can it transform to other format, like 201901160102 ?
Copy link to clipboard
Copied
Sure
alert(myFile.modified.getTime());
Copy link to clipboard
Copied
THANKS!
Copy link to clipboard
Copied
Actually, I just re-read your second reply, where you want to format time. Here's one approach to that. Feel free to juggle around to format it your way. Also read more about Date() format here Date | MDN
var myFile = File('pathToFile.js');
var modified = myFile.modified;
var formatedTime = formatDate(modified);
alert(formatedTime);
function formatDate(date) {
var year = date.getFullYear();
var month = date.getMonth() + 1; // In JS world month starts at 0, not 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var result = year + pad(month) + pad(day) + pad(hours) + pad(minutes) + pad(seconds);
return result;
}
function pad(value, padding) {
padding = padding || 2;
var string = value.toString();
while (string.length < 2) {
string = '0' + string;
}
return string;
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more