You can convert an ISO8601 timestamp into a JavaScript Date object and write the date into a spreadsheet cell like this:
const ss = SpreadsheetApp.getActive();
const cell = ss.getRange('Sheet1!A2');
const timestamp = cell.getDisplayValue();
const date = new Date(timestamp);
cell.setValue(date);
The datetime in the cell will be shown in the timezone set in File > Settings > Time zone. It will represent the same moment as the UTC timestamp. If you want to display the time in GMT, choose the GMT (no daylight saving) timezone.
To convert the date into a text string that represents another timezone, use Utilities.formatDate(), like this:
const ss = SpreadsheetApp.getActive();
const timezone = ss.getSpreadsheetTimeZone();
const cell = ss.getRange('Sheet1!A2');
const timestamp = cell.getDisplayValue();
const date = new Date(timestamp);
cell.setValue(Utilities.formatDate(date, timezone, 'yyyy-MM-dd HH:mm'));
You can also set timezone
to a long format string such as 'America/New_York'
, as listed by Joda.org.
Google Sheets will automatically convert certain types of text strings into numerical values. You can take advantage of that like this:
const ss = SpreadsheetApp.getActive();
const cell = ss.getRange('Sheet1!A2');
const timestamp = cell.getDisplayValue();
const dateString = timestamp.replace('Z', '');
cell.setValue(dateString);
Note that the datetime value in the target cell will refer to a moment in time that differs from the the timestamp, unless you set the spreadsheet's timezone to GMT.
You can also convert timestamps to dateserial values with a spreadsheet formula like this:
=datevalue(left(A2, 10)) + timevalue(mid(A2, 12, 12))
...or, taking a shortcut:
=value(left(A2, len(A2) - 1))
Format the result cell as Format > Number > Date time. Again, note that the value will not refer to the same moment as the timestamp, unless the spreadsheet's timezone is GMT.
See Working with date and time values in Google Sheets and Working with Dates and Times in Apps Script.