Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript date + 1

How do I take today's date and add 1 day to it?

If possible, inline please?

like image 375
Rod Avatar asked Feb 01 '11 21:02

Rod


People also ask

What is new Date () in JavaScript?

It is used to work with dates and times. The Date object is created by using new keyword, i.e. new Date(). The Date object can be used date and time in terms of millisecond precision within 100 million days before or after 1/1/1970.

What Date format is dd mm yyyy in JavaScript?

To format a date as dd/mm/yyyy: Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .

What does new Date () return?

"The expression new Date() returns the current time in internal format, as an object containing the number of milliseconds elapsed since the start of 1970 in UTC.


2 Answers

This will get tomorrow's date:

var a = new Date((new Date()).valueOf() + 1000*3600*24); 
like image 80
cambraca Avatar answered Oct 08 '22 22:10

cambraca


You have to use the getDate() and setDate() methods of the Date object which respectively get and set the day value of the date.

var date = new Date(); date.setDate(date.getDate() + 1); 

Check the MDC Date object reference for more information on working with dates

like image 45
Tom Tu Avatar answered Oct 08 '22 21:10

Tom Tu