【发布时间】:2021-10-18 09:46:06
【问题描述】:
我很确定这是一个小问题,但我只是不知道如何解决它,因为我是使用 Apps 脚本的新手 :(。
问题:
我有一张由 2 列组成的表格:A 和 B。A 列包含以德语格式(日/月/年)书写的日期。示例:2021 年 10 月 18 日写成 18/10/2021。现在我要做的就是每天从 A 列增加 1 天,然后在 B 列中写入结果(因此,增加的天数)。
尝试的解决方案:
我已经想出了如何增加天数并将结果写在 B 列中。但我正在努力添加脚本的第二部分,以便在 B 列中用德语写出增加的日期(请参阅下面的脚本)。
问题:
如何以及在何处将“Utilities.formatDate()”包含到我的代码中,以便 B 列中的日期以德语格式化? (所以,DAY/MONTH/YEAR 而不是 MONTH/DAY/YEAR)?
非常感谢您的帮助。
// Increment dates in colum A by 1 day and write this incremented date in colum B
function incrementDateInGermanFormat() {
var ss = SpreadsheetApp.getActiveSheet();
var date = new Date(ss.getRange(1, 1).getValue());
ss.getRange(1, 2).setValue(new Date(date.setDate(date.getDate() + 1)));
}
// This is the line I´m having trouble to include in the script above
Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy")
【问题讨论】:
-
@Kos - 感谢您的提示。我已经尝试了该链接上代码的许多变体......徒劳无功。你还有什么可以推荐给我的更符合我问题的特殊性的吗?谢谢:)
标签: date google-apps-script google-sheets