javascript date + 1

后端 未结 7 1320
逝去的感伤
逝去的感伤 2020-12-29 02:34

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

If possible, inline please?

相关标签:
7条回答
  • 2020-12-29 02:51

    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.

    0 讨论(0)
  • 2020-12-29 02:52
    dt = new Date();
    dt.setDate(dt.getDate() + 1);
    
    0 讨论(0)
  • 2020-12-29 02:54

    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);
    });
    
    0 讨论(0)
  • 2020-12-29 02:56

    Try this:

    //create the date
    var myDate = new Date();
    
    //add a day to the date
    myDate.setDate(myDate.getDate() + 1);
    
    0 讨论(0)
  • 2020-12-29 03:05

    This will get tomorrow's date:

    var a = new Date((new Date()).valueOf() + 1000*3600*24);
    
    0 讨论(0)
  • 2020-12-29 03:07
    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);
    
    0 讨论(0)
提交回复
热议问题