阅读与学习从Google Spreadsheets撰写日期 [英] Reading & writing dates from Google Spreadsheets

查看:46
本文介绍了阅读与学习从Google Spreadsheets撰写日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Apps脚本从一个Google Spreadsheet导入近30,000个日期到另一个.我从10,000张纸上导入的效果很好,但较大的那张纸效果不佳.对于较大的导入,所有日期都将被导入为过去的1个日期,因此1/1/2018变为12/31/2017,依此类推.

I am importing almost 30,000 dates from one Google Spreadsheet to another with a Google Apps Script. My import from a sheet of 10,000 works fine, but the larger one doesn't. For the larger import, all dates are being imported 1 date in the past, so 1/1/2018 becomes 12/31/2017, etc.

我知道Javascript处理日期有些不同,所以我不确定为什么它在一个上失败而在另一个上工作.但是大多数情况下,我不确定如何一次增加整个数组(实际上是数组的数组).

I know Javascript handles dates a bit unusually, so I'm not sure why it's failing on one and working on the other. But mostly, I'm not sure how to increment the entire array (actually array of arrays) at once).

当我在GAS调试器中检查日期值时,我注意到返回的日期是2018年1月1日,即Sun Dec 31 17:00:00 GMT-07:002017.工作表返回的是Mon Jan 01 00:00:00 GMT-06:002018.我检查了脚本文件和基础电子表格的属性,并且两者均设置为GMT-7.

When I checked the date values in the GAS debugger, I noticed that the January 1, 2018 date was being returned as Sun Dec 31 17:00:00 GMT-07:00 2017. The working sheet is returning Mon Jan 01 00:00:00 GMT-06:00 2018. I checked the properties on both script files and the underlying spreadsheets, and both are set to GMT-7.

编辑

前12行日期:
2018年1月1日
2018年1月1日
2018年1月1日
2018年1月1日
2018年1月1日
2018年1月1日
2018年1月1日
不适用
不适用
2018年1月1日
2018年1月2日

EDIT

First 12 rows of dates:
January 1, 2018
January 1, 2018
January 1, 2018
January 1, 2018
January 1, 2018
January 1, 2018
January 1, 2018
N/A
N/A
January 1, 2018
January 2, 2018

输出: 2017年12月31日
2017年12月31日
2017年12月31日
2017年12月31日
2017年12月31日
2017年12月31日
2017年12月31日
不适用
不适用
2017年12月31日
1/1/2018

Output: 12/31/2017
12/31/2017
12/31/2017
12/31/2017
12/31/2017
12/31/2017
12/31/2017
N/A
N/A
12/31/2017
1/1/2018

我正在使用的代码是destination.getRange(1,7,lastRow+1).setValues(source.getRange(2,columns[0],lastRow+1).getValues()); 我知道这可能是时区问题,但尤其是在整个阵列中,我不知道该怎么办.

The code I'm using is destination.getRange(1,7,lastRow+1).setValues(source.getRange(2,columns[0],lastRow+1).getValues()); I understand is is probably a timezone issue, but especially across an entire array, I don't know what to do about it.

期望的行为:输出是源数据第一行的精确副本.

Desired behavior: The output to be an exact copy from the first rows of the source data.

我希望这很清楚/很好.如果还有其他需要取消的操作,请告诉我.

I hope that is clear/good enough. If there's anything else I need to do to get this out of on-hold, please let me know.

推荐答案

答案是通过尝试使用注释中的内容来完成的,所以我要对此进行回答,以实际给出发生的情况.

The answer came through trying things from the comments, so I'm answering this to actually give what happened.

我已经在Google Sheets UI中签入了 File> Spreadsheet Settings ,并从脚本编辑器中签入了 File> Project Properties ,以验证时区设置是否为一样-他们是.

I had checked in File > Spreadsheet Settings in the Google Sheets UI, and File > Project Properties from the Script Editor, to verify that the time zone settings were the same - and they were.

但是,当我运行 getSpreadsheetTimeZone() 在脚本编辑器中,其输出为空白.我手动将时区更改为其他时区,然后将其改回,最后脚本识别了时区,问题得以解决.

However, when I ran getSpreadsheetTimeZone() from the Script Editor, its output was blank. I manually changed the timezone to something else and then changed it back, and finally the script recognized the timezone and the issue was resolved.

我无法说出是什么原因导致了Google表格的时区设置错误,只有正确设置才可以使所有工作正常.

I can't say what caused the Google Sheet's timezone setting to be wrong, only that getting it right made it all work.

这篇关于阅读与学习从Google Spreadsheets撰写日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆