How do I take today\'s date and add 1 day to it?
If possible, inline please?
If by "add 1 day to it" you mean "add 24 hours", that is, add 24*60*60*1000 milliseconds to a JavaScript date object, then the correct solution is:
var d = new Date();
d.setTime(d.getTime() + 86400000);
console.log('24 hours later');
console.log(d);
As @venkatagiri pointed out in an earlier comment, this will in fact add 24 hours to the current JavaScript date object in all scenarios, while d.setDate(d.getDate() + 1)
will NOT if a Daylight Savings Time cross-over is involved. See this JSFiddle to see the difference in context of the 2013 start of DST (at March 10, 2013 at 2:00 AM, DST locale time moved forward an hour). setDate()
in this scenario only adds 23 hours, while setTime()
adds 24.
dt = new Date();
dt.setDate(dt.getDate() + 1);
Add 30 days and set the date value to datepicker
Example :
$(document).ready(function() {
var myDate = new Date();
//add a day to the date
myDate.setDate(myDate.getDate() + 30);
var end_date = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate());
$('#datepicker').datepicker({
format: 'dd-mm-yyyy',
orientation: 'bottom'
});
$('#datepicker').datepicker('setDate', end_date);
});
Try this:
//create the date
var myDate = new Date();
//add a day to the date
myDate.setDate(myDate.getDate() + 1);
This will get tomorrow's date:
var a = new Date((new Date()).valueOf() + 1000*3600*24);
var d = new Date();
var curr_date = d.getDate();
var n =curr_date;
jQuery(".class_name:eq(0)").text(n);
var m =[d.getDate()+1];
jQuery(".class_name:eq(1)").text(m);