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

172
Views
How to change a date format in JavaScript

I have a date in following format:

13 Dec,2021 12:59:58

and I want to change it into:

13-12-2021

pls suggest some fix

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

0

Convert it do a Date, get the make a string out of the components.

The month needs to add 1 since for some reason, months are zero-indexed (January == 0, February == 1, ..., December == 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

You can do something like this

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

You can use moment.js to do this.

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!