AIR中的日期操作

时间:2011-01-18 20:25:20

标签: air

我有:

targetFile = air.File.desktopDirectory.resolvePath('myFolder' + files[f].name);
files[f].moveTo(targetFile,true); // Overwrite

我想在覆盖之前制作targetFile的备份副本。

也许是带有日期时间戳的东西,这样我就有了无限的备份,当然会定期清除(读:每个蓝月亮一次)。

1 个答案:

答案 0 :(得分:1)

(function() {
    Date.prototype.toYMD = Date_toYMD;
    function Date_toYMD() {
        var year, month, day;
        year = String(this.getFullYear());
        month = String(this.getMonth() + 1);
        if (month.length == 1) {
            month = "0" + month;
        }
        day = String(this.getDate());
        if (day.length == 1) {
            day = "0" + day;
        }
        return '' + year + month + day;
    }
})();

(function() {
    Date.prototype.toHMS = Date_toHMS;
    function Date_toHMS() {
        var hour, minute, second;
        hour = String(this.getHours());
        minute = String(this.getMinutes());
        second = String(this.getSeconds());
        return '' + hour + minute + second;
    }
})();

然后

var dt = new Date();
var ArcBakFile = air.File.desktopDirectory.resolvePath('myDir/myFile.' + dt.toYMD() + '.' + dt.toHMS() + '.txt');