Home >Web Front-end >JS Tutorial >How Can I Increment a JavaScript Date Object by One Day?
Incrementing a JavaScript Date Object by One Day
You have a Date object and wish to increment it by one day using JavaScript's Date object. Here's an improved solution for your code:
Replace your current code with the following to add one day to the Date object:
var date = new Date(); // add a day date.setDate(date.getDate() + 1); var ds = stringFormat("{day} {date} {month} {year}", { day: companyname.i18n.translate("day", language)[date.getUTCDay()], date: date.getUTCDate(), month: companyname.i18n.translate("month", language)[date.getUTCMonth()], year: date.getUTCFullYear() });
This code:
Using this method, you can increment the date object by any number of days. For example, to increment by two days, you would use date.setDate(date.getDate() 2).
The above is the detailed content of How Can I Increment a JavaScript Date Object by One Day?. For more information, please follow other related articles on the PHP Chinese website!