【发布时间】:2020-08-14 01:47:42
【问题描述】:
我想连接两个单元格值。示例:
单元格日期的值:2020 年 5 月 11 日。单元格时间的值:14:00。最终细胞 应该是:2020-05-11 14:00:00。
我这样做的方式是:
sheetDestination.getRange(9,7).setValue(shiftDate + shiftTime);
输出结果是:
2020 年 5 月 11 日星期一 00:00:00 GMT-0400(东部夏令时间)范围。
function shiftDuration () {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetDestination = spreadsheet.getSheetByName("NewToImport");
//Time Diff
var timeStartforShift = sheetDestination.getRange(2, 4).getDisplayValue(); //start time
var timeEndforShift = sheetDestination.getRange(5, 5).getDisplayValue(); //end time
var shiftDuration = Math.floor(parseInt(timeEndforShift) - parseInt(timeStartforShift));
//create a new row to test concatenating date and time
var rangeDurantionToCopy = sheetDestination.getRange(1, 1, 2,
sheetDestination.getMaxColumns());
rangeDurantionToCopy.copyTo(sheetDestination.getRange(8,1));
var shiftEndTime = sheetDestination.getRange(9,5).setValue(timeStartforShift + (shiftDuration * 60));
var shiftDate = sheetDestination.getRange(9,3).getValue();//get the Date for the shift
sheetDestination.getRange(9,7).setValue(shiftDate + shiftEndTime);
}
下面是函数。我正在添加工作表的图片。基本上时间表显示一个班次(4小时班次),每行表示同一班次1小时。
我正在尝试将其设置为 1 行,开始和结束时间显示为 4 小时轮班。例如从上午 10 点到下午 2 点,并且有一个单元格需要日期 + 时间(输出太错误了!)
【问题讨论】:
-
您认为在字符串连接中尝试使用
setValue方法的调用会返回什么?
标签: javascript google-apps-script google-sheets