Php 如何获得一周的前几天和后几天

Php 如何获得一周的前几天和后几天,php,Php,大家好,我正在用我的日历建房子 我正在尝试为我的日历获取当前月份的前一天和后一天。事实上,日历已经开始工作了,但与我的笔记本电脑的时间不一样 我必须更改此代码中的某些内容吗 $month = 9; $year = 2013; // calculate the number of days in the current month $day_count = cal_days_in_month(CAL_GREGORIAN, $month, $year); // get number of d

大家好,我正在用我的日历建房子

我正在尝试为我的日历获取当前月份的前一天和后一天。事实上,日历已经开始工作了,但与我的笔记本电脑的时间不一样

我必须更改此代码中的某些内容吗

$month = 9;
$year  = 2013;

// calculate the number of days in the current month 
$day_count = cal_days_in_month(CAL_GREGORIAN, $month, $year);

// get number of days for the next month 
$pre_days = (6 - (date('w', mktime(0, 0, 0, $month, $day_count, $year))));

// get number of days after the month 
$post_days = date('w', mktime(0, 0, 0, $month, 1, $year));
然后我做一个循环来显示日期

echo "<div id='cal_wrapper'>";
echo    "<div class='title_bar'>";
echo        "<div class='prev_month'></div>";
echo        "<div class='show_month'></div>";
echo        "<div class='next_month'></div>";
echo    "</div>"; // end title bar

echo    "<div class='week_days'>";
        foreach($weekDaysArr as $value)
        {
echo        "<div class='days_of_week'>".$value."</div>";

        }
echo   "<div class='clear'></div>";
echo    "</div>"; // end week days

        // Previous Month Filler
        if($pre_days != 0) {
            for($i = 1; $i <= $pre_days; $i++)
            {
echo            "<div class='non_cal_days'></div>";
            }
        }

        // Current day of the month filler
        if($day_count != 0 )
        {
            for($x = 1; $x <= $day_count; $x++)
            {
echo           "<div class='cal_days'>";
echo                "<div class='day_header'>".$x."</div>";
echo            "</div>";
            }
        }

        // Current day of the month filler
        if($post_days != 0 )
        {
            for($y = 1; $y <= $post_days; $y++)
            {
echo            "<div class='non_cal_days'></div>";
            }
        }

echo "</div>"; // end calendar wrapper
echo”“;
回声“;
回声“;
回声“;
回声“;
回声“;//结束标题栏
回声“;
foreach($value为工作日)
{
回显“$value.”;
}
回声“;
回声“;//周末天数
//上月填料
如果($pre_days!=0){

对于($i=1;$i将时区添加到脚本中:

<?php
    date_default_timezone_set('America/Los_Angeles');
    // or         date_default_timezone_set('Europe/Berlin');
    .
    .
    .

更多信息

对我来说是这样的

<?php
    $now = date ( 'Y-m-j G:i:s' );
    echo 'pre_days--> '. $pre_days = date ( 'Y-m-j G:i:s', strtotime ( '-6 day' . $now ) );
    echo '<br />'; 
    echo 'post_days--> '. $post_days = date ( 'Y-m-j G:i:s', strtotime ( '+1 year' . $now ) );
?>


你在本地主机上吗?你设置了时区吗?是的,在本地主机上。不,我没有设置时区查看一下这个构建日历的解决方案>先生,我已经设置了时区,但仍然没有得到确切的日期。先生,日期现在是准确的了…谢谢..但是我如何使用它来获得前一天和后一天..抱歉这样的问题..我不知道不确定$month=9;$year=2013;是否应该始终保持不变或改变。你也可以在strotimesir中使用这些变量,你得到的是哪一天?(你可以删除一些评论,因为你没有足够的分数去聊天。)$now=date('Y-m-j G:i:s');$days='-6天';echo'sixDaysBeforeNow-->。$sixDaysBeforeNow=date('Y-m-j G:i:s',strotime($days.$now));
<?php
    $now = date ( 'Y-m-j G:i:s' );
    echo 'pre_days--> '. $pre_days = date ( 'Y-m-j G:i:s', strtotime ( '-6 day' . $now ) );
    echo '<br />'; 
    echo 'post_days--> '. $post_days = date ( 'Y-m-j G:i:s', strtotime ( '+1 year' . $now ) );
?>