【问题标题】:calendar array previous next month下个月上一个日历数组
【发布时间】:2017-05-13 03:23:00
【问题描述】:

所以我正在创建一个日历应用程序以放入网站,它应该:

  • 显示当前月份
  • 显示接下来 (3) 个月
  • 显示前 2 个月
  • 显示上个月的结束和下个月的开始(如果布局允许)(就像 windows 日历一样。)

所以现在我的代码为我生成了一个包含所有数据的数组,它会自动使其从正确的位置开始并且(根据每月的第一天)并设置默认天数到 42。(这就是 windows 的做法。)

这是数组输出:https://pastebin.com/NqLzNW5Z 这是我的 Calendar.class.php 文件:https://pastebin.com/Hin8q7xW(有些词是荷兰语,对不起。)

我的问题:如何更改以下内容:

        [7] => Array
            (
                [0] => Before Month Start
                [1] => Before Month Start
                [2] => Before Month Start
                [3] => 01-06-2017
                [4] => 02-06-2017
                [5] => 03-06-2017
                [6] => 04-06-2017
                [7] => 05-06-2017
                [8] => 06-06-2017
                [9] => 07-06-2017
                [10] => 08-06-2017
                [11] => 09-06-2017
                [12] => 10-06-2017
                [13] => 11-06-2017
                [14] => 12-06-2017
                [15] => 13-06-2017
                [16] => 14-06-2017
                [17] => 15-06-2017
                [18] => 16-06-2017
                [19] => 17-06-2017
                [20] => 18-06-2017
                [21] => 19-06-2017
                [22] => 20-06-2017
                [23] => 21-06-2017
                [24] => 22-06-2017
                [25] => 23-06-2017
                [26] => 24-06-2017
                [27] => 25-06-2017
                [28] => 26-06-2017
                [29] => 27-06-2017
                [30] => 28-06-2017
                [31] => 29-06-2017
                [32] => 30-06-2017
                [33] => After month
                [34] => After month
                [35] => After month
                [36] => After month
                [37] => After month
                [38] => After month
                [39] => After month
                [40] => After month
                [41] => After month
            )

到这样的事情:

        [7] => Array
            (
                [0] => 29-05-2017
                [1] => 30-05-2017
                [2] => 31-05-2017
                [3] => 01-06-2017
                [4] => 02-06-2017
                [5] => 03-06-2017
                [6] => 04-06-2017
                [7] => 05-06-2017
                [8] => 06-06-2017
                [9] => 07-06-2017
                [10] => 08-06-2017
                [11] => 09-06-2017
                [12] => 10-06-2017
                [13] => 11-06-2017
                [14] => 12-06-2017
                [15] => 13-06-2017
                [16] => 14-06-2017
                [17] => 15-06-2017
                [18] => 16-06-2017
                [19] => 17-06-2017
                [20] => 18-06-2017
                [21] => 19-06-2017
                [22] => 20-06-2017
                [23] => 21-06-2017
                [24] => 22-06-2017
                [25] => 23-06-2017
                [26] => 24-06-2017
                [27] => 25-06-2017
                [28] => 26-06-2017
                [29] => 27-06-2017
                [30] => 28-06-2017
                [31] => 29-06-2017
                [32] => 30-06-2017
                [33] => 01-07-2017
                [34] => 02-07-2017
                [35] => 03-07-2017
                [36] => 04-07-2017
                [37] => 05-07-2017
                [38] => 06-07-2017
                [39] => 07-07-2017
                [40] => 08-07-2017
                [41] => 09-07-2017
            )

注意:可以看到的第一个月和最后一个月不必显示前一个月和后一个月。因为这需要我再加载一个月。就这几天。

最终结果将与滑块放在一起。当用户点击下个月箭头时,滑块将显示下个月。

如果有人知道如何帮助我完成这项工作,请告诉我。如果有人知道更好的方法,也请告诉我!

谢谢

【问题讨论】:

    标签: php arrays calendar


    【解决方案1】:

    这是未经测试的,所以如果您遇到任何问题,请告诉我。

        public function makeMonth($m, $y)
        {
    
            $maand = array();
            // Get info for this year
            $info = $this->getInfo($m, $y);
    
            // Get array with dates
            $amount = $info['days'];
            $dateStart = strtotime("{$y}-{$m}-1");
            for ($i = 1; $i <= $amount; $i++) {
                $maand[$i] = str_pad($i, 2, '0', STR_PAD_LEFT) . "-" . $m . "-" . $y;
                $dateEnd = strtotime("{$y}-{$m}-{$i}");
            }
    
            // place the array content correctly
            $needed = 42;
            $begin = $info['firstday'] - 1;
            $nognodig = $needed - ($begin + $amount);
    
            #begin van array
            while ($begin > 0) {
                $begin--;
                $dateStart = strtotime("-1 day", $dateStart);
                array_unshift($maand, date("d-m-Y", $dateStart));
            }
    
            #eind van array
            while ($nognodig > 0) {
                $nognodig--;
                $dateEnd = strtotime("+1 day", $dateEnd);
                array_push($maand, date("d-m-Y", $dateEnd));
            }
        }
    

    【讨论】:

    • 谢谢,这行得通。我将“d-M-Y”更改为“d-m-Y”。所以它显示数字。非常感谢!接受你的回答。
    • 更新的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多