How to get yesterday's date with Momentjs?

后端 未结 8 865
清酒与你
清酒与你 2021-01-30 08:08

So, my question is simple, how do I get yesterday\'s date with MomentJs ? In Javascript it is very simple, i.e.

today = new Date();
yesterday = new Date(today.se         


        
8条回答
  •  执念已碎
    2021-01-30 08:31

    Simplest Solution

    By using moment we can easily get Yesterday, Today and Tomorrow Date

    1. Get Yesterday Date:

    moment().subtract(1, "days").format("YYYY-MM-DD");
    

    2. Get Today Date:

    moment().subtract(0, "days").format("YYYY-MM-DD");
    

    3. Get Tomorrow Date:

    moment().subtract(-1, "days").format("YYYY-MM-DD");
    

提交回复
热议问题