Javascript - Get Previous Months Date

后端 未结 6 903
情深已故
情深已故 2021-02-14 12:25

If i have a variable that returns a date, in the format of dd MMM yyyy, so 28 Aug 2014, how can i get the date of the previous month.

I can modify the month via:

6条回答
  •  独厮守ぢ
    2021-02-14 13:15

    There is my way to get previous months.

    const formatter = new Intl.DateTimeFormat("default", {
      month: "long"
    });
    const date = new Date();
    
    let number = 1;
    let prevMonth = formatter.format(
      new Date(date.getFullYear(), date.getMonth() - `${number}`)
    );
    

提交回复
热议问题