让我的星期日开始于星期一而不是星期日

时间:2016-04-14 10:59:51

标签: php html calendar

我一直在寻找方法让这个日历在星期一而不是星期日开始。

我一直在尝试很多不同的东西,比如$ firstDayArray ['wday'] - 1,但事情是它会再创建一个空白空间,这样就可以让日历跳过一天。

任何形式的帮助都会很棒! P.s我是一个巨大的菜鸟,但是想练习。我一直在寻找这个伟大网站的几乎每个角落的答案,还没找到它。

<?php
define("ADAY", (60*60*24));
if ((!isset($_POST['month'])) || (!isset($_POST['year']))){
    $nowArray =getdate();
    $month = $nowArray['mon'];
    $year = $nowArray['year'];
} else {
    $month = $_POST['month'];
    $year = $_POST['year'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<!DOCTYPE html>

<html>
<head>
<title><?php echo "Calendar:".$firstDayArray['month']."
".$firstDayArray['year']; ?>
</title>
<meta charset="utf-8">
<meta lang="da">
<link type="text/css" rel="stylesheet" href="calendar_style.css">
</head>
<body>
<form align="center" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<select name="month">
<?php
$months = Array("Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August",
"September", "Oktober", "November", "December");
for ($x=1; $x <= count($months); $x++) {
    echo"<option value=\"$x\"";
    if ($x == $month) {
        echo " selected";
    }
    echo ">" .$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=2016; $x<=2018; $x++) {
    echo "<option";
    if ($x == $year) {
        echo " selected";
    }
    echo ">$x</option>";
}
?>
</select>
<button type="submit" name="submit" value="submit">Gå til måned</button>

</form>
<br>

<?php
$days = Array("Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn");
echo "<table><tr>\n";
foreach ($days as $day) {
    echo "<th>" .$day."</th>\n";
}
for ($count=0; $count < (6*7); $count++) {
    $dayArray = getdate($start);
    if (($count % 7) == 0) {
        if ($dayArray['mon'] != $month) {
            break;
        } else {
            echo "</tr><tr>\n";
        }
    }
    if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {
        echo "<td>&nbsp;</td>\n";
    } else {
        echo "<td>" .$dayArray['mday']."</td>\n";
        $start += ADAY;
    }
}
echo "</tr></table>";
?>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

您可以使用Bootstrap 3作为输入。 你可以禁用几周的日子(坐着,晒太阳) https://eonasdan.github.io/bootstrap-datetimepicker/

这个

<div class="container">
<div class="col-sm-6" style="height:130px;">
    <div class="form-group">
        <div class='input-group date' id='datetimepicker11'>
            <input type='text' class="form-control" />
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar">
                </span>
            </span>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('#datetimepicker11').datetimepicker({
            daysOfWeekDisabled: [0, 6]
        });
    });
</script>

答案 1 :(得分:0)

尝试以下方法,它有效:

<?php
$days = Array("Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn");
echo "<table><tr>\n";
foreach ($days as $day) {
    echo "<th>" .$day."</th>\n";
}
for ($count=0; $count < (6*7); $count++) {
    $dayArray = getdate($start);
    if ((($count + 7) % 7) == 0) {
        if ($dayArray['mon'] != $month) {
            break;
        } else {
            echo "</tr><tr>\n";
        }
    }
    if ($count < ($firstDayArray['wday'] + 6) || $dayArray['mon'] != $month) {
        echo "<td>&nbsp;</td>\n";
    } else {
        echo "<td>" .$dayArray['mday']."</td>\n";
        $start += ADAY;
    }
}
echo "</tr></table>";
?>