Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

401
Views
¿Cómo formatear fechas JSON con JavaScript?

Tengo un HTML <input type="date" name="departing" /> que devuelve, por ejemplo, la fecha en el siguiente formato: 2021-11-07

Cuando reenvío esta variable a mi manillar, se muestra de la siguiente manera:

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

Me gustaría que se muestre como:

 07/11/2021

Intenté formatearlo con date-fns así:

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

Pero luego mi manillar muestra: "Invalid Date"

Estoy muy confundido. ¿Alguna idea sobre cómo hacer que esa fecha se muestre en el formato 11/07/2021?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

En primer lugar, cree un objeto de fecha.

 const newDate = new Date();

Ahora puedes manipular el código para obtener la respuesta que quieras.

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

La salida se verá como el 11/01/2021

about 4 years ago · Juan Pablo Isaza Report

0

Bueno, podrías ir tan simple como usar los métodos #getDate(), #getMonth() y #getFullYear() por separado y luego mostrarlos en el orden que te gustaría:

 const date = new Date(departing); const day = date.getDate(); const month = date.getMonth() + 1; const year = date.getFullYear(); console.log(`${day}/${month}/${year}`);

Espero que responda la pregunta.

about 4 years ago · Juan Pablo Isaza Report

0

Podrías hacerlo de varias formas

Método 1:-

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

método 2: obtener valores separados y combinar

 let n = new Date() console.log(n.getDate()+"/"+n.getMonth()+"/"+n.getFullYear()) output=== 31/9/2021
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!