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

JQuery / Javascript convert date from format "yyyy-mm-dd" to readable string

I am using an input field to get a date which is stored as "yyyy-mm-dd" and I want to convert it to a more readable format to display with html, so 2000-05-03 will look something like May 3, 2000. Is there an easy way to do this?

>Solution :

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

Yes, you can use toLocateDateString() for it. And with the options format the date.

For your example it will be like this:

const date = new Date("2000-05-03");
date.toLocaleString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })
console.log(date);

Will print May 3, 2000

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