Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

62
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda