是只有我一个人,还是谷歌最近有什么变化?我有一个向编辑添加时间戳的函数,它工作得很好,但就在前几天它坏了。
它打破了过去在我的时区中标记时间的意义-正如我使用的格式化函数所指定的那样,现在它似乎是在GMT而不是GMT-8中标记时间戳。我的脚本没有任何变化,那么发生了什么呢?
function happyFunTime() {
var s = SpreadsheetApp.getActiveSheet();
var r = s.getActiveCell();
var columnNum = r.getColumn();
var timeLastCalledColumnOffset = getTimeLastCalledColumnOffset();
var rowNum = r.getRow();
if (rowNum <=1) return;
timeLastCalledColumnOffset++;
// set dateCell = the current row at column J
var dateCell = s.getRange(rowNum, timeLastCalledColumnOffset);
var tZone= "GMT-8";
// Format the current date into datetime format
var dateTime = Utilities.formatDate(new Date(), tZone, "MMM-dd-yyyy h:mm a");
// Set the cell value. Add apostrophe to force text treatment & keep the spreadsheet from reformatting
dateCell.setValue("'" + dateTime);
}getTimeLastCalledColumnOffset()是一个自定义函数,用于返回包含我感兴趣的值的列的编号(J,因此在本例中为9)。
发布于 2012-12-16 06:12:41
是的,昨天有一个问题,因为这个字符串"GMT-2“或"GMT-0200”一直工作正常,但现在有问题。
您可以更改此行:
var tZone= "GMT-8"到这一个
var tZone= "GMT-08:00"或者,您可以使用以下代码行获取时区:
var FUS1 = new Date().toString().substr(25,8); // I use FUS1 instead of tZone
// GMT-0800 -> GMT-08:00 , ...
var FUS1 = FUS1.substr(0,6) + ':' + FUS1.substr(6)
// Format the current date into datetime format
var dateTime = Utilities.formatDate(new Date(), FUS1 , "MMM-dd-yyyy h:mm a");或者,您可以从此处写入您的时区:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
“美国/道森”-> -08:00 (我不知道你住在哪里:-( )
这段代码是:
var dateTime = Utilities.formatDate(new Date(), "America/Dawson" , "MMM-dd-yyyy h:mm a");注意:如果要格式化从DateBox捕获的日期(标签、文本框等)然后,最后一行可以是这样的:
var dateTime = Utilities.formatDate(new Date(e.paramameter.datebox), "America/Dawson" , "MMM-dd-yyyy h:mm Sergi
发布于 2012-12-17 18:56:01
获得要包含在Utilities.formatDate()中的正确字符串的另一个简单的解决方案是使用Session.getTimeZone(),它返回例如'Europe/Paris',在我的例子中是一个有效的参数。
发布于 2018-01-30 13:42:43
我们可以使用下面的代码行直接更改电子表格的时区
SpreadsheetApp.getActive().setSpreadsheetTimeZone(Session.getScriptTimeZone())
https://stackoverflow.com/questions/13895586
复制相似问题