Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

transform date yyyy-mm-ddTHH:mm:ssZ to dd-mm-yyyy javascript react

I need to transform this date that comes from an API in this format

yyyy-mm-ddTHH:mm:ssZ

to

dd-mm-yyyy

do I have to use any library in order to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It should be what you need:

let theDate=new Date("2022-07-26T03:00:11.183Z");
let option={
    day:"2-digit",
    month:"2-digit",
    year:"numeric",
}
let result=theDate.toLocaleDateString('en-US',option).replaceAll("/","-")
console.log(result);

If you want the output in dd-mm-yyyy format, you can replace "en-US" with "en-GB".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading