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

后端 未结 15 1560
情歌与酒
情歌与酒 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: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

提交回复
热议问题