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

176
Views
Cómo cambiar un formato de fecha en JavaScript

Tengo una fecha en el siguiente formato:

 13 Dec,2021 12:59:58

y quiero cambiarlo a:

 13-12-2021

los pls sugieren alguna solución

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

0

Conviértalo en una Date , obtenga una cadena de los componentes.

El mes debe agregar 1 ya que, por alguna razón, los meses están indexados a cero (enero == 0, febrero == 1, ..., diciembre == 11)

 const dateString = "13 Dec,2021 12:59:58"; const getNewString = (dateString) => { const date = new Date(dateString); return `${date.getDate()}-${date.getMonth()+1}-${date.getFullYear()}`; } console.log(getNewString(dateString));

about 4 years ago · Juan Pablo Isaza Report

0

puedes hacer algo como esto

 const oldDate = "13 Dec,2021 12:59:58"; const newDate = new Date(oldDate); console.log(newDate.getDate() + "-" + (newDate.getMonth() + 1) + "-" + newDate.getFullYear());

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar moment.js para hacer esto.

 console.log(moment('13 Dec,2021 12:59:58').format('DD-MM-YYYY'))
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>

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!