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

How to add days to today? javascript

How to add days to today in day-month-year format?
I tried this code but additionally get the time zone and month in the short word name.
I want to receive, for example, August 12, 2023
here is the code:

Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}

var date = new Date();

console.log(date.addDays(5));

>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

To get the format: Month Day, Year, Simply use ECMAScript Internationalization API:

return date.toLocaleString('en-us',{month:'long', year:'numeric', day:'numeric'})
month:'long' //August
day:'numeric' //12
year:'numeric' //2023

Note: ‘long’ uses the full name of the month, ‘short’ for the short name,

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