Format date and Subtract days using Moment.js

后端 未结 7 883
别那么骄傲
别那么骄傲 2020-11-29 20:28

I would like a variable to hold yesterday\'s date in the format DD-MM-YYYY using Moment.js. So if today is 15-04-2015, I would like to subtract a day and have 1

7条回答
  •  一个人的身影
    2020-11-29 21:06

    I think you have got it in that last attempt, you just need to grab the string.. in Chrome's console..

    startdate = moment();
    startdate.subtract(1, 'd');
    startdate.format('DD-MM-YYYY');
    "14-04-2015"
    
    startdate = moment();
    startdate.subtract(1, 'd');
    myString = startdate.format('DD-MM-YYYY');
    "14-04-2015"
    myString
    "14-04-2015"
    

提交回复
热议问题