Running in App script, google sheet. I get timestamp from API and return this result:
[[1.6370611672429312E18], [1.63706107263277082E18], [1.63706100204943616E18], [1.63706094340754534E18], [1.63706078474499994E18], [1.63706064715950106E18], [1.63706061367677235E18], [1.63706061367677082E18], [1.63706061367676902E18], [1.63706061367676749E18], [1.63706061367676595E18], [1.63706061367676442E18]],
Now I want to convert this timestamp to date to be like that: 10/28/2021 10:30
I try this code: var convertDate = Utilities.formatDate(timestamp, "GMT", "MM-dd-yyyy HH:mm:ss");
but not working any suggestoin
Advertisement
Answer
Assuming those timestamps are in nanoseconds, create a Date by dividing the timestamp value by a million.
const timestamps = [[1.6370611672429312E18], [1.63706107263277082E18]]; for (let i = 0; i < timestamps.length; i++) { const timestamp = new Date(timestamps[i][0] / 1000000); const convertDate = Utilities.formatDate(timestamp, "GMT", "MM-dd-yyyy HH:mm:ss"); }