【发布时间】:2015-05-11 11:12:01
【问题描述】:
我对 Google Apps 脚本还很陌生,所以请多多包涵。
我在 Google 表格上从一家银行收集每日利率,我正在使用以下代码为 A5:F5 中包含的利率附加新行,其中 A 列包含日期。
function recordHistory() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Interest Rates");
var source = sheet.getRange("A5:F5");
var values = source.getValues();
values[0][0] = Utilities.formatDate(new Date(), "GMT+10:00", "yyyy-MM-dd");
sheet.appendRow(values[0]);
};
我的问题是 - 虽然我已将日期格式指定为“yyyy-MM-dd”,但我的新行中 A 列中的日期是以这种格式“M/dd/yyyy”创建的。
我已尝试使用 Google 表格中的下拉格式菜单将整个 A 列预格式化为“yyyy-MM-dd”,但如果我在上面运行代码,我的新行仍处于“M/dd/yyyy”中.
就好像我的代码完全忽略了 Utilities.formatDate。仅供参考,我从here 获得了上述代码。
【问题讨论】:
-
删除了那部分,干杯
标签: date google-apps-script format google-sheets