如何处理此类电子表格中的日期。
我需要从第2列获取最后一个日期,然后找到下一个日期。我已创建此代码以检索上一个日期。
lastDateRow = sheet.getLastRow()-1;
lastDate = Date(sheet.getRange("B"+(lastDateRow)+":B"+(lastDateRow).getValue());
答案 0 :(得分:1)
您从工作表中获得的值已经是日期对象(包括年份,日期,小时等),不需要进一步操作。
当你说“下一次约会”时,我猜你的意思是“第二天”?如果是这样,只需在日期中添加24 * 60 * 60 * 1000(以毫秒为单位),您将在第二天获得; - )
在代码中它变成这样:
function xxx(){
var sheet = SpreadsheetApp.getActiveSheet()
var lastDateRow = sheet.getLastRow();
var lastDate = sheet.getRange(lastDateRow,2).getValue();
Logger.log(lastDate)
var nextDay = new Date(lastDate.getTime()+24*60*60*1000);
Logger.log(nextDay)
}
测试记录器结果:
Tue Aug 21 15:00:00 PDT 2012
Wed Aug 22 15:00:00 PDT 2012
答案 1 :(得分:1)
实际上这是我在堆栈溢出后查找js nextdate fnction后最终得到的结果。
var lastDateRow = sheet.getLastRow();
var lastDate = sheet.getRange(lastDateRow,2).getValue();
lastDate = getTomorrow(lastDate,1);
function getTomorrow(d,offset) {
if (!offset) { offset = 1 }
return new Date(new Date(d.getTime()).setDate(d.getDate() + offset));
}