英文:
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");
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论