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

397
Visualizações
How to format JSON dates with JavaScript?

I have an HTML <input type="date" name="departing" /> which returns for example the date in the following format: 2021-11-07

When I forward this variable to my handlebars, it is being displayed as follows:

Mon Nov 08 2021 01:00:00 GMT+0100 (Central European Standard Time)

I would like to have it displayed as:

07/11/2021

I tried formatting it with date-fns like this:

departing = format(parseISO(departing.getDate()), "dd/MM/yyyy");

But then my handlebar shows: "Invalid Date"

I am so confused. Any ideas on how to get that date to be displayed in the 07/11/2021 format?

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

0

First of all create a date object

const newDate = new Date();

Now you can manipulate code to get answer whatever you want

var outputDate = newDate .getDate() + "/" +  (newDate.getMonth()+1) + "/" + 
newDate.getFullYear();

Output will be looks like 01/11/2021

about 4 years ago · Juan Pablo Isaza Relatório

0

Well you could go as simple as using #getDate(), #getMonth() and #getFullYear() methods separately then displaying them in the order you'd like like so:

const date = new Date(departing);
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();

console.log(`${day}/${month}/${year}`);

Hope it answers the question.

about 4 years ago · Juan Pablo Isaza Relatório

0

You could do it by several ways

method 1:-

let n = new Date()
console.log(n.toLocaleDateString("en-US")
output=== 31/9/2021

method 2 :- get separate values and merge

let n = new Date()
console.log(n.getDate()+"/"+n.getMonth()+"/"+n.getFullYear())
output=== 31/9/2021
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