Skip to content Skip to sidebar Skip to footer

Parsing Time From Google Sheets To Html And Date Information Is Being Added

I'm parsing data from a google sheet to a html table. One of the cells only has time information but I'm still getting date information. Here is a code snipit: Logger.log('Date:

Solution 1:

Date objects in javaScript are always complete dates with year, month, day,hours... even if the spreadsheet has only time value in a cell.

When the script reads a time value in SS it converts it to a full date object, to show the date values (date or time, the origin object is exactly the same) use

Utilities.formatDate(data[k][q], Session.getScriptTimeZone(), "hh:mm");

to send a string to your HTML Ui instead of a date object.

`Session.getScriptTimeZone()`

gets the time zone from your script so that hours (and dates in certain conditions) show the right values.

For this to work correctly you have to check the time zone settings of your spreadsheet as well, and the one of your script. Both should be set to your country of course.

Post a Comment for "Parsing Time From Google Sheets To Html And Date Information Is Being Added"