我需要创建一个函数,该函数将一个单元格设置为当前时间 + 15分钟。

huangapple go评论90阅读模式
英文:

I need to make a function that sets a cell to current time +15 minutes

问题

function firstbreak() {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1,3).setValue(new Date(new Date().getTime() + 15*60000)).setNumberFormat("h:mm AM/PM")

}

英文:
function firstbreak() { 
   var sheet = SpreadsheetApp.getActiveSheet();
   sheet.getRange(1,3).setValue(new Date).setNumberFormat("h:mm AM/PM")

}

I have the function working properly to set the cell to current time. How can I get the function to set the cell to current time +15 minutes?

答案1

得分: 2

function firstbreak() { 
  var sheet = SpreadsheetApp.getActiveSheet();
  var now = new Date();
  var fifteenMinutesLater = new Date(now.getTime() + (15 * 60 * 1000));
  sheet.getRange(1, 3).setValue(fifteenMinutesLater).setNumberFormat("h:mm AM/PM");
}
英文:

I suggest

function firstbreak() { 
  var sheet = SpreadsheetApp.getActiveSheet();
  var now = new Date();
  var fifteenMinutesLater = new Date(now.getTime() + (15 * 60 * 1000));
  sheet.getRange(1, 3).setValue(fifteenMinutesLater).setNumberFormat("h:mm AM/PM");
}

huangapple
  • 本文由 发表于 2023年4月6日 23:04:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定