date - Apps 脚本:如何将英文日期格式转换为德文日期格式?
问题描述
我很确定这是一个小问题,但我只是不知道如何解决它,因为我是使用 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")
解决方案
将日期转换为字符串是不好的做法。在这种情况下,更好的选择是在电子表格用户界面中将 B 列的日期格式简单地更改为德语或.setNumberFormat("dd/mm/yyyy")
在 B 列上使用。
推荐阅读
- django - 代码应该打印特定用户的帖子,但它正在打印所有用户的帖子
- mysql - 是否可以创建这样的 MySQL 查询?
- java - Java JPA - 如何使用列表放置对象并使用 CRUD 更新列表对象?
- angular - 导入模块以在其他模块中部分使用
- ios - iOS - 是否可以通过编程方式拨打电话阻止任何类型的拨出电话声音?
- xcode - react-native - 升级后链接失败:ld:未找到架构 x86_64 的符号
- python - vimeo api python 使用关键字搜索视频
- python - 类型错误:运行 2to3 后 pyshipping.Package 实例之间不支持“<”
- vb.net - VB.net同步文件夹和文件
- r - 在所有 NA 的情况下,R 将行总和返回为零