0

このコードは私にとってはうまく機能していますが、今日 (セルを変更したとき)、スクリプトが実際の日付より 1 か月遅れた日付を生成していることに気付きました (つまり、今日は 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);
  }

}
4

1 に答える 1