JavaScript how to get tomorrows date in format dd-mm-yy

后端 未结 15 1538
情歌与酒
情歌与酒 2020-11-29 02:31

I am trying to get JavaScript to display tomorrows date in format (dd-mm-yyyy)

I have got this script which displays todays date in format (dd-mm-yyyy)



        
相关标签:
15条回答
  • 2020-11-29 02:52

    you can try this:

    function Tomorrow(date=false) {
        var givendate = (date!=false) ? new Date(date) : new Date();
        givendate.setDate(givendate.getDate() + 1);
        var day = givendate.getUTCDate()
        var month = givendate.getUTCMonth()+1
        var year = givendate.getUTCFullYear()
        result ="<b>" + day + "/" + month + "/" + year + "</b>";
        return result;
    } 
    var day = Tomorrow('2020-06-30');
    console.log('tomorrows1: '+Tomorrow('2020-06-30'));
    console.log('tomorrows2: '+Tomorrow());

    0 讨论(0)
  • 2020-11-29 02:55

    I would use the DateJS library. It can do exactly that.

    http://www.datejs.com/

    The do the following:

    var d = new Date.today().addDays(1).toString("dd-mm-yyyy");
    

    Date.today() - gives you today at midnight.

    0 讨论(0)
  • 2020-11-29 02:58

    Using JS only(Pure js)

    Today

    new Date()
    //Tue Oct 06 2020 12:34:29 GMT+0530 (India Standard Time)
    new Date(new Date().setHours(0, 0, 0, 0))
    //Tue Oct 06 2020 00:00:00 GMT+0530 (India Standard Time)
    new Date(new Date().setHours(0, 0, 0,0)).toLocaleDateString('fr-CA')
    //"2020-10-06"
    

    Tomorrow

    new Date(+new Date() + 86400000);
    //Wed Oct 07 2020 12:44:02 GMT+0530 (India Standard Time)
    new Date(+new Date().setHours(0, 0, 0, 0) + 86400000);
    //Wed Oct 07 2020 00:00:00 GMT+0530 (India Standard Time)
    new Date(+new Date().setHours(0, 0, 0,0)+ 86400000).toLocaleDateString('fr-CA')
    //"2020-10-07"
    //don't forget the '+' before new Date()
    

    Day after tomorrow

    Just multiply by two ex:- 2*86400000

    You can find all the locale shortcodes from https://stackoverflow.com/a/3191729/7877099

    0 讨论(0)
提交回复
热议问题