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

202
Visualizações
Get Day Name from Date in JS

enter image description here

Hello guys, i need some help over here, hope that you can provide me the solution.

How can i transform this Date format to a Format that shows the names of the days.

I know that i can use something like this but i dont know how to add that when im mapping data from an object or array.

let getDayName = (dateStr, locale) => {
    let date = new Date(dateStr);
    // console.log(date.toLocaleDateString(locale, { weekday: 'long' }));
    return date.toLocaleDateString(locale, { weekday: 'long' });
  };

 let dateStr = date;

enter image description here

enter image description here

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

0

You can add another map declaration and do it there like so:

.filter(() => {})
.map((item) => {
    item.dt_txt = getDayName(item.dt_txt);
    return item;
})
.map(() => {})
about 4 years ago · Juan Pablo Isaza Relatório

0

You are on the right track. Only thing missing is, that you need to call your function getDayName() and provide sufficient arguments.

Here an example:

const array = ["2022-05-30 18:00:00", "2022-05-30 17:00:00", "2022-05-25 18:00:00"]

const getDayName = (dateStr, locale) => {
  let date = new Date(dateStr);
  return date.toLocaleDateString(locale, { weekday: 'long' });
};

const output = array.map(dateStr => getDayName(dateStr, "en-GB"))

console.log(output)
.as-console-wrapper { max-height: 100% !important; top: 0; }

In your case you are already mapping using map(), therefore you would just need to call your function within the callback of map():

<!-- other code... -->
<div className="fd-day">
    <h1>{getDayName(item.dt_txt, "en-GB")}</h1>
</div>
<!-- some more code... -->

instead of

<!-- other code... -->
<div className="fd-day">
    <h1>{item.dt_txt}</h1>
</div>
<!-- some more code... -->

Of course you can adjust the locale to whatever fits your needs.

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