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

233
Vistas
JavaScript: Generate current date with custom format

I am trying to generate the current date in the Date Month, Year format. Currently I am using following code:

function currentDate() 
{
    var months = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    ];

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    return `${d} ${months[m]}, ${y}`;
}

Although, It's works perfectly. But, is there a shorter way to do this..?

Something like:

(new Date()).format('d M, Y')
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Unfortunately, there isnt.

But you can use libraries like luxon:

DateTime.now().toFormat('d M, Y')

Or, if you want to stay native, you can use Intl.DateTimeFormat:

new Intl.DateTimeFormat('es-US', { dateStyle: 'full' }).format(d);

However, ECMAScript currently has a proposal to improve Date class by adding Temporal global object:

Temporal.now.date().toLocaleString('es-US', {
  weekday: 'long',
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

There is no simple way to do that. Instead, you could see other alternatives.

If you are already using new Date() all over the application. I suggest dayjs. It has all the date-utilities you are looking for.

It works with new Date() object also.

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