Error fix
Fix wrong time zone in Apps Script timestamps
apps script timezone wrong
Format timestamps with Utilities.formatDate and the spreadsheet time zone, so the text written to the cell does not depend on the script's zone.
Set it up
- Set File > Settings > Time zone in the sheet.
- Set the same zone in Project Settings (Show appsscript.json manifest file).
- Use stampNow to write text timestamps.
The script
/**
* Fix: timestamps show the wrong time.
* Format dates with an explicit time zone instead of relying on the default string.
* Also set the zone in Project Settings (appsscript.json "timeZone").
*/
function stampNow(sheet, row, col) {
var tz = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone();
var text = Utilities.formatDate(new Date(), tz, 'yyyy-MM-dd HH:mm:ss');
sheet.getRange(row, col).setValue(text);
return text;
}What you should see
| Written value |
|---|
| 2026-11-14 10:02:31 |
Same moment, formatted in the sheet zone. Sample values, not output from a real account.
Common errors and fixes
- The sheet and script show different times
- They have separate time zone settings. Set both.
- Dates become text
- stampNow writes text. Write new Date() instead when you need a real date cell.
Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.
TriggerShelf is independent and not affiliated with or endorsed by Google LLC. Google Sheets, Gmail, Google Drive and Apps Script are trademarks of Google LLC. Quota figures come from Google's Apps Script quotas page. Test on a copy first.