How to get yesterday date in node.js backend?

后端 未结 8 975
误落风尘
误落风尘 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:23

    I would take a look at moment.js if you are interested in doing calculations with dates, there are many issues you can run into trying to do it manually or even with the built in Date objects in JavaScript/node.js such as leap years and daylight savings time issues.

    http://momentjs.com/

    For example:

    var moment = require('moment');
    var yesterday = moment().subtract(1, 'days');
    console.log(yesterday.format());
    

提交回复
热议问题