简体   繁体   中英

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. 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. 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)".

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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