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

171
Views
How to convert date from react calendar in the dd/mm/yyyy format?

I am using react-calendar , Here I am getting a date in the following format

Wed Feb 02 2022 00:00:00 GMT+0530 (India Standard Time) 

Now I am trying to convert it to dd/mm/yyyy. is there any way though which I can do this ?

Thanks.

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

0

You could use the methods shown in this blogpost https://bobbyhadz.com/blog/javascript-format-date-dd-mm-yyyy from Borislav Hadzhiev.

You could a new date based on your calendar date and afterwards format it:

function padTo2Digits(num) {
  return num.toString().padStart(2, '0');
}

function formatDate(date) {
  return [
    padTo2Digits(date.getDate()),
    padTo2Digits(date.getMonth() + 1),
    date.getFullYear(),
  ].join('/');
}

console.log(formatDate(new Date('Wed Feb 02 2022 00:00:00 GMT+0530 (India Standard Time)'))); 
about 4 years ago · Juan Pablo Isaza Report

0

The native Date object comes with seven formatting methods. Each of these seven methods give you a specific value -

  • toString() : Fri Jul 02 2021 14:03:54 GMT+0100 (British Summer Time)
  • toDateString(): Fri Jul 02 2021
  • toLocaleString() : 7/2/2021, 2:05:07 PM
  • toLocaleDateString() : 7/2/2021
  • toGMTString() : Fri, 02 Jul 2021 13:06:02 GMT
  • toUTCString() : Fri, 02 Jul 2021 13:06:28 GMT
  • toISOString() : 2021-07-02T13:06:53.422Z

var date = new Date();

// toString()
console.log(date.toString());

// toDateString()
console.log(date.toDateString());

// toLocalString()
console.log(date.toLocaleString());

// toLocalDateString()
console.log(date.toLocaleDateString());

// toGMTString()
console.log(date.toGMTString());

// toGMTString()
console.log(date.toUTCString());

// toGMTString()
console.log(date.toISOString());

Format Indian Standard time to Local time -

const IndianDate = 'Wed Feb 02 2022 00:00:00 GMT+0530 (India Standard Time)';

const localDate = new Date(IndianDate).toLocaleDateString();

console.log(localDate);

about 4 years ago · Juan Pablo Isaza Report

0

This is JavaScript default date format.

You can use libraries like momentjs, datefns, etc to get the result.

For example, if you are using momentjs:-

moment(date).format('dd/mm/yyyy);

Or if you don't want to use any third-party library you can get the result from JavaScript's default date object methods.

const date = new Date();

const day = date.getDate() < 10 ? 0${date.getDate()} : date.getDate(); const month = date.getMonth() + 1 < 10 ? 0${date.getMonth() + 1} : date.getDate() + 1; const year = date.getFullYear();

const formattedDate = ${day}/${month}/${year};

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!