这段代码对我来说效果很好,但是今天(当我修改了一个单元格时)我注意到脚本生成的日期比实际日期晚了一个月(即今天是 2013 年 6 月 5 日,但是脚本生成了2013 年 5 月 5 日)。谁能看到可能导致此问题的原因?
// * based on the script "insert last modified date" by blisterpeanuts@gmail.com *
// Update cell with the the last modified time of any (single) cell in that row, excluding row 1 and column 1
function onEdit() {
var d = new Date();
// format date nicely
var month_str = d.getMonth();
var day_str = d.getUTCDate();
var year_str = d.getYear().toString().substring(2);
// create the formatted time and date strings
var date_str = month_str + '/' + day_str + '/' + year_str;
// create the message (change this to whatever wording you prefer)
// note also that rather than all the above, you could just use d.toString()
// I didn't because I didn't want it printing the timezone.
var s = date_str;
var active_range = SpreadsheetApp.getActiveRange();
if (active_range.getHeight() == 1 && active_range.getWidth() == 1 && active_range.getRow != 1 && active_range.getColumn() != 1) {
var update_row = active_range.getRow().toString();
var update_cell = "AF" + update_row;
SpreadsheetApp.getActiveSheet().getRange(update_cell).setValue(s);
}
}