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

66
Visualizações
How can I get 3 letter day of week and 3 letter month using vanilla JavaScirpt Date object?

I need to get "Jun" for "June" and "Mon" for "Monday". The problem is looking up in an object of english words doesn't work if user has their language set to anything other than English.

export const shortDate = (str: any) => {
    const d = new Date(str);
    const dateString =
        daysOfWeek[d.getDay()].toUpperCase() +
        ', ' +
        shortMonths[d.getMonth()] +
        ' ' +
        d.getDate() +
        nth(d.getDate());

    return dateString;
};

I need to get rid of the shortMonths object and the dayOfWeek since this will be different when user is not English speaker.

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

0

Check out Intl.DateTimeFormat:

var date = new Date();

var options = { weekday: 'short', month: 'short' };
console.log(new Intl.DateTimeFormat('en-US', options).format(date));

Or as Sebastian points out above, date.toLocaleString:

const date = new Date()

console.log(date.toLocaleString('en-US', { weekday: 'short' }))
console.log(date.toLocaleString('en-US', { month: 'short' }))

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