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

198
Vistas
How to get only the date part of GMT in JavaScript?

Here's my date string:

2022-07-20T11:34:39

And here's my code to get GMT:

new Date('2022-07-20T11:34:39').toGMTString()
// prints this
// Wed, 20 Jul 2022 07:04:39 GMT

However, I only need the date part. Wed, 20 Jul 2022. I know I can use substring or regex or split etc. to extract it.

Is there any solution to achieve this without those tricks?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

First of all toGMTString() is depracated:

Note: toGMTString() is deprecated and should no longer be used. It remains implemented only for backward compatibility; please use toUTCString() instead.

You are looking for toDateString():

const res = new Date('2022-07-20T11:34:39').toDateString()
console.log(res)

Or more configurable toLocaleDateString():

const options = {
  weekday: 'short',
  year: 'numeric',
  month: 'short',
  day: 'numeric'
};
const res = new Date('2022-07-20T11:34:39').toLocaleDateString('en-US', options)
console.log(res)

about 4 years ago · Santiago Trujillo Denunciar

0

use Intl.DateTimeFormat

const dateFormatter = new Intl.DateTimeFormat('en-GB', {
  year: 'numeric',
  month: 'long',
  day: 'numeric',
  weekday: 'short'
})

const dateFormatter2 = new Intl.DateTimeFormat('en-GB', {
  dateStyle: 'full'
})

const cdate = new Date()

console.log(dateFormatter.format(cdate));
console.log(dateFormatter2.format(cdate));

about 4 years ago · Santiago Trujillo 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