你可以在这里看到我想做什么,http://perthurbanist.com/website/calendarloader.php。基本上,它是一个水平日历,您将使用箭头来移动。我想要做的是让代码水平显示所有月份以及所有日期(从当前月份和日期开始)。我知道如何使用date函数获取当前日期,但我不知道如何让日历从该日期开始。我还希望它能加载很多个月(可能需要2-3年)。我该怎么做这两件事。
<?php
$showday = date("j");
$displaymonth = date("M");
$showmonth = date("n");
$showyear = date("Y");
$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
echo '<ul class="calendarnavigation">';
echo '<li class="month">' . $displaymonth . '</li>';
for($i=1; $i<= $day_count; $i++) {
echo '<li>' . $i . '</li>';
}
echo '</div>';
?>发布于 2012-09-23 17:09:15
如果你知道(或者能够计算出你想在几天内走多远,你可以尝试这样做:
for($i=0; $i<$numberOfDays; $i++)
{
$timestamp=mktime(0,0,0,date("m"),date("d")+$i,date("Y"));
$day=date("d", $timestamp);
$month=date("m", $timestamp);
$year=date("Y", $timestamp);
...Your display stuff here...
}在循环的每一次迭代中,$timestamp将前进一天,在date函数中使用它将为您提供有关创建显示所需日期的信息。
也许在你的情况下,你可以使用
echo '<ul class="calendarnavigation">';
for($i=0; $i<$numberOfDays; $i++)
{
$timestamp=mktime(0,0,0,date("m"),date("d")+$i,date("Y"));
$showday=date("j", $timestamp);
$displaymonth=date("M", $timestamp);
$showmonth=date("n", $timestamp);
$showyear=date("Y", $timestamp);
if($showday=="1")
{
echo '<li>'.$displaymonth.'</li>';
}
echo '<li>'.$showday.'</li>';
}
echo '</ul>';https://stackoverflow.com/questions/12550949
复制相似问题