怎么递增递减获取上月下月的时间天数

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

怎么递增递减获取上月下月的时间天数

具体什么意思 ,举个例子

不知道对不对,大概就是这个思路吧。

img

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        /**
         * 获取月份天数
         */
        function getMonthDays(offset) {
            let cur = new Date()
            let tar = new Date(cur.getFullYear(), cur.getMonth() + offset + 1, 0)
            console.log(tar.toDateString());
            return tar.getDate();
        }

        console.log("四月", getMonthDays(0));
        console.log("三月", getMonthDays(-1));
        console.log("二月", getMonthDays(-2));
        console.log("一月", getMonthDays(-3));
        console.log("去年十二月", getMonthDays(-4)); 
    </script>
</body>

</html>