简体   繁体   English

Google脚本的自定义日期格式

[英]Custom date formatting for Google Scripts

Okay so I'm pretty new to Google scripts, but I was able to find code online for exactly what I needed, which allows a Google Spreadsheet to automatically update a Fusion Table. 好的,我是Google脚本的新手,但是我可以在线找到符合我需要的代码,这可以让Google电子表格自动更新Fusion Table。 The code is pretty massive so I won't post the whole thing, but you can find it here . 该代码非常庞大,因此我不会将其全部发布,但是您可以在这里找到它。

It works great, but the only problem is that the date used in the Fusion Table isn't formatted the same way as it is in the spreadsheet. 效果很好,但唯一的问题是Fusion Table中使用的日期格式与电子表格中的日期格式不同。 In the spreadsheet it is formatted the way I want, which is "1/25/2015 19:21:02", while in the table it is "Sun Jan 25 2015 19:21:02 GMT-0000 (GMT)". 在电子表格中,该文件的格式为我想要的格式,即“ 1/25/2015 19:21:02”,而在表格中,其格式为“ Sun Jan 25 2015 19:21:02 GMT-0000(GMT)”。

I noticed the following lines of script and tried changing them but it didn't help: 我注意到以下脚本行并尝试更改它们,但无济于事:

{function processSpreadsheetValue(column, value, sqlStatements, updating) {
var safeValue;
if (column === 'Timestamp') {
//   Ensure this is a format Fusion Tables understands
safeValue = Utilities.formatDate(new Date(value), "GMT",
    "dd/MM/yyyy' 'HH:mm:ss");}

But this did not fix it. 但这并没有解决。 Any help would be greatly appreciated, thanks! 任何帮助将不胜感激,谢谢!

It sounds like the date is being passed into your Fusion table correctly, but you need to adjust the formatting in the Table itself. 听起来好像日期已正确传递到Fusion表中,但是您需要调整表本身的格式。

To do this, open the fusion table and hover over the header of your date column. 为此,请打开融合表并将鼠标悬停在日期列的标题上。 Click the Down arrow and choose "Change". 单击向下箭头,然后选择“更改”。

Make sure the Type is set to "Date/Time", then choose the desired format from the list. 确保“类型”设置为“日期/时间”,然后从列表中选择所需的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM