How to get yesterday date in node.js backend?

后端 未结 8 978
误落风尘
误落风尘 2021-02-09 14:00

I am using date-format package in node back end and I can get today date using

var today = dateFormat(new Date());

In the same

8条回答
  •  滥情空心
    2021-02-09 14:20

    Extract yesterday's date from today

    //optimized way 
            var yesterday = new Date();
            yesterday.setDate(yesterday.getDate()-1);
            console.log(yesterday) // log yesterday's date 
    
    
    //in-detail way 
            var today = new Date();
            var yesterday = new Date();
            yesterday.setDate(today.getDate()-1);
            console.log(yesterday) // log yesterday's date
    

提交回复
热议问题