Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert timestamp from API to date app script

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading