【发布时间】:2014-09-21 05:51:44
【问题描述】:
我是箭头的两个图像,一个箭头向后增量一个,一个通过href递增它的一个。
if (ISSET($_GET["month"])){
$month_index = $_GET["month"];
}
else{
$month_index = 0;
}
$month = strtotime("+".$month_index." month");
?>
...
<a href=<?php $month_index = $month_index - 1; echo "?month=".$month_index; ?>><img src="arrow_left.gif" ></a>
<div class="title">Logbook Calendar for <?php echo date("F Y",$month); ?> </div>
<a href=<?php $month_index = $month_index + 2; echo "?month=".$month_index; ?>><img src="arrow_right.gif"></a>
问题在于,当 2015 年 2 月到来时,date() 返回“2015 年 3 月”——所以 $month_index = 6 和 $month_index = 7 都是三月。
我在http://writecodeonline.com/php/上运行了这段代码:
date_default_timezone_set("America/New_York");
$month_index = 6;
$month_index = $month_index - 1;
$month_index = $month_index + 2;
echo $month_index;
$month = strtotime("+".$month_index." month");
echo " " . $month;
echo " " . date("F Y",$month);
将 $month_index=6 切换为 $month_index=7 仍会导致 3 月的回显。 2015 年 2 月……已经过去了吗?
更新:谢谢大家。我永远不会自己找到那个。我这样解决了这个问题:
$month = strtotime(date("M-01-Y") . "+".$month_index." month");
【问题讨论】:
-
一块字符串的长度? span>
-
@Fred-ii- php.net/manual/en/function.strlen.php ;)
-
@AmagicalFishy 哈哈!好的;)很高兴看到你有一种幽默感:) span>
标签: php date datepicker