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

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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