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

258
Visualizações
How to get just the day from ISO string javascript

I have an ISO date coming back from a server and before I send it to the frontend I want to convert the ISO date to something like this

2011-10-05T14:48:00.000Z

time: {
          day: 'Tue',
          hour: '11:54 AM',
          date: 'May 5, 2019'
        }

I dont want to use a bunch of regex unless I have to, I was hoping I could achieve this with just functions like .toDateString() etc... is there a toDateDayString or something like that?

Here is the snippet of the actual function sending the info back to my frontent.

Id like to be able to to this inline from a promise in .then()

allMessages = [] 

await subClient.conversations.services(convoServiceSid)
           .conversations(convo)
           .messages
           .list({limit: 20})
           .then(messages => messages.forEach(m =>
 allMessages.push({"messagesId": m.conversationSid, "time": m.dateCreated.toDateString() }) ));
//m.dateCreated is always going to be an ISO string, I want to make an object with day, hour, date if possible

res.json(allMessages)

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

0

I think you can do it like this:

const date = new Date('2011-10-05T14:48:00.000Z');
const format = {
   day: date.getDay(),
   hour: `${date.getHours()} ${date.getMinutes()}`,
   date: `${date.getMonth()} ${date.getFullYear()}`
};
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use toLocaleDateString method

function get_time(iso_date_str) {
  const [day, month_date, year, hour] = (
    new Date(iso_date_str).toLocaleDateString('en', {
      weekday: 'short',
      hour: 'numeric',
      minute: 'numeric',
      month: 'short',
      day: 'numeric',
      year: 'numeric',
    })
    .split(/,\s?/)
  );
  return {
    day,
    hour,
    date: month_date + ', ' + year
  };
}

console.log(get_time('2011-10-05T14:48:00.000Z'));

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