我希望显示日期和日期从当前月份开始直至接下来的两个月,如下所示:
tue wed thu
1 2 3
Aug Aug Aug
依此类推,在这种情况下直到10月(2个月)。
如何使用PHP和JQuery完成这项工作?
答案 0 :(得分:0)
像这样:
<?php
$from = new \DateTime();
$to = new \DateTime('+2 months');
for ($from; $from < $to; $from->modify('+1 day')) {
echo $from->format('D d M').PHP_EOL;
}
输出:
Wed 30 Aug
Thu 31 Aug
Fri 01 Sep
Sat 02 Sep
Sun 03 Sep
Mon 04 Sep
Tue 05 Sep
...
Mon 30 Oct
如果您需要显示器,可以执行以下操作:
<?php
$from = new \DateTime();
$to = new \DateTime('+2 months');
$dates = [];
for ($from; $from < $to; $from->modify('+1 day')) {
$dates[] = [
'numerical day' => $from->format('d'),
'text day' => $from->format('D'),
'text month' => $from->format('M'),
];
}
echo implode(' ', array_column($dates, 'text day')).PHP_EOL;
echo ' '.implode(' ', array_column($dates, 'numerical day')).PHP_EOL;
echo implode(' ', array_column($dates, 'text month')).PHP_EOL;
将输出:
Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon
30 31 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Aug Aug Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Sep Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct Oct