目前我正在使用 jQuery 日历插件来显示我构建的日历。所有数据都是使用 PHP 从 SQL 数据库中填写的。我正处于日历中,我需要及时开始向前和向后移动。我在一周和一个月的时间里都遇到了很多麻烦。就白天而言,这还不错。
这是我今天的代码
function startTime() {
$today = getdate();
$startTime = mktime(8, 0, 0, $today["mon"], $today["mday"]+$_SESSION['number'], $today["year"]);}
然后我传入$startTime
另一个发出 SQL 请求的函数。 $_SESSION[
'number']
如果之前没有设置,则设置为 0,否则我根据用户是点击下一个还是上一个来加 1 或减 1。endTime()
几乎是相同的功能。
如果可能的话,我只想对我的startTime()
和endTime()
功能进行更改。
这是用于计算日/周/月的凌乱且未经测试(我们的服务器关闭 atm)的代码
function startTime($type)
{
$today = getDate();
$startTime = mktime(8, 0, 0, $today["mon"], $today["mday"]+$_SESSION['number'], $today["year"]);
if ($type == "day")
{
$startTime = mktime(8, 0, 0, $today["mon"], $today["mday"]+$_SESSION['number'], $today["year"]);
}
if ($type == "week")
{
if ($today['w'] == 0)
{
$startTime = mktime(8, 0, 0, $today["mon"], $today["mday"]+($_SESSION['number'] * $_SESSION['multiplier']), $today['year']);
}
else
{
$day = strtotime("last Sunday");
$today = getdate($day);
$startTime = mktime(8, 0, 0, $today["mon"], $today["mday"]+($_SESSION['number'] * $_SESSION['multiplier']), $today['year']);
}
}
if ($type == "month")
{
$startTime = mktime(8, 0, 0, $today["mon"]+($_SESSION['number']), 0, $today['year']);
}
return $startTime;
}
function endTime(type)
{
$today = getdate();
$endTime = mktime(20, 0, 0, $today["mon"], $today["mday"]+$_SESSION['number'], $today["year"]);
if ($type == "day")
{
$endTime = mktime(20, 0, 0, $today["mon"], $today["mday"]+$_SESSION['number'], $today["year"]);
}
if ($type == "week")
{
if ($today['w'] == 6)
{
$endTime = mktime(20, 0, 0, $today["mon"], $today["mday"]+($_SESSION['number'] * $_SESSION['multiplier']), $today['year']);
}
else
{
$day = strtotime("next Saturday");
$today = getdate($day);
$endTime = mktime(20, 0, 0, $today["mon"], $today["mday"]+($_SESSION['number'] * $_SESSION['multiplier']), $today['year']);
}
}
if ($type == "month")
{
$day = strtotime("next month - 1 hour");
$today = getdate($day);
$endTime = mktime(8, 0, 0, $today["mon"]+($_SESSION['number']), $today["mday"], $today['year']);
}
return $endTime;
}
我要感谢大家的时间,这是我的第一篇文章,所以如果我的帖子中有任何不良做法,请告诉我。我搜索了stackoverflow,并在谷歌上搜索了解决此问题的方法,但还没有找到。