计算下一个月

108 阅读1分钟

知道字符串,如果根据该字符串,计算该字符串对应的下一个月的时间

字符串 2021年3月

    const replaceMonth = (str) => {
        const [year, month] = str.match(/\d+/g);

        if (Number(month) === 12) {
          return `${Number(year) + 1}年1月`;
        } else {
          return `${year}${Number(month) + 1}月`;
        }
    }