Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
convert timestamp to one array

Running in App script, google sheet. I get the timestamp from API and return this result:

[[1.6370611672429312E18], [1.63706107263277082E18]], 

I do this code and work fine, but the problem is not in the array, I need it every time in an array:

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

the result is:

1:52:34 PM  Info    11-16-2021 12:52:33
1:52:34 PM  Info    11-16-2021 12:52:33
1:52:34 PM  Info    11-16-2021 12:52:33

I need results like that: 1:52:34 PM Info [[11-16-2021 12:52:33], [11-16-2021 12:50:10]]

to put in sheet by this code: sheet.getRange(1,1,convertDate .length, convertDate [0].length).setValues(convertDate );

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

const timestamps = [[1.6370611672429312E18], [1.63706107263277082E18]];
const toISOStringWithTimezone = date => {
  const pad = n => `${Math.floor(Math.abs(n))}`.padStart(2, '0');
  return date.getFullYear() +
    '-' + pad(date.getMonth() + 1) +
    '-' + pad(date.getDate()) +
    ' ' + pad(date.getHours()) +
    ':' + pad(date.getMinutes()) +
    ':' + pad(date.getSeconds())
};
const hasArrDate = (data = []) => {
  return data.flat().map(v => toISOStringWithTimezone(new Date(v / 1000000)))
}
console.log(hasArrDate(timestamps));
about 4 years ago · Juan Pablo Isaza Relatório

0

const timestamps = [[1.6370611672429312E18], [1.63706107263277082E18]];
let convertedDates = []; // Create an array to store the converted dates
for (let i = 0; i < timestamps.length; i++) {
  const timestamp = new Date(timestamps[i][0] / 1000000);
  const convertedDate = Utilities.formatDate(timestamp, "GMT", "MM-dd-yyyy HH:mm:ss");
  convertedDates.push([convertedDate]); // Wrap each in [] because this will be printed as a single column
}

const sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
sheet.getRange(1, 1, convertedDates.length, convertedDates[0].length).setValues(convertedDates);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda