Javascript code for showing yesterday's date and todays date

前端 未结 5 1925
面向向阳花
面向向阳花 2020-12-02 18:29

How to show yesterday\'s date in my textbox the yesterday\'s date and at the same time, the today\'s date in ?

I have this home.php where I show the date yesterday(

5条回答
  •  猫巷女王i
    2020-12-02 18:48

    Get yesterday date in javascript

    You have to run code and check it output

        var today = new Date();
        var yesterday = new Date(today);
        
        yesterday.setDate(today.getDate() - 1);
        console.log("Original Date : ",yesterday);
    
        const monthNames = [
      "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    ];
        var month = today.getMonth() + 1
        yesterday = yesterday.getDate() + ' ' + monthNames[month] + ' ' + yesterday.getFullYear()
       
        console.log("Modify Date : ",yesterday);

提交回复
热议问题