我正在尝试找出当前日期和文件创建日期之间的天数。目的是删除距离当前日期不超过 4 天的文件。
我使用了下面的应用程序脚本,但差异在控制台中给了我一个“NaN”输出
function iterateFolder() {
var folder = DriveApp.getFolderById('XXXXXXXXXXX');
console.log('Folder: ', folder.getName());
var files = folder.getFiles();
var currentDate = new Date();
var modifiedDate = Utilities.formatDate(currentDate, 'Australia/Adelaide', 'dd-MM-yyyy');
console.log('Now: ', modifiedDate);
while(files.hasNext()){
var file = files.next();
var createdDate = file.getDateCreated();
var modifiedCreatedDate = Utilities.formatDate(createdDate, 'Australia/Adelaide', 'dd-MM-yyyy');
console.log('File: ', file.getName(), ' Created On: ', modifiedCreatedDate);
console.log('Difference: ', modifiedDate - modifiedCreatedDate); // Gives NaN
}
}