【发布时间】:2016-12-03 06:57:57
【问题描述】:
根据我对 PHP 的有限知识和能力,以下代码应该可以工作:
<?php
////DISPLAY DATE OF NEXT COUNCIL MEETING////
$now = date('U'); //get current time
$firstTues = strtotime("-1 month first Tuesday 4pm"); //get first Tuesday of the month
$secondTues = strtotime("-1 month second Tuesday 5pm"); //get second Tuesday of the month
$fourthTues = strtotime("-1 month fourth Tuesday 5pm"); //get forth Tuesday of the month
$nextTues = strtotime("first Tuesday 4pm"); //get first Tuesday of next month
function nextCouncilMeeting() {
//If todays date less than 1st Tuesday at 11pm, display date for 1st Tuesday 4pm.
if ($now < $firstTues) {
echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A', $firstTues);
}
//If todays date greater than 1st Tuesday 5pm and less than 2nd Tuesday 11pm, display date for 2nd Tuesday 5pm
elseif ($now > $firstTues and $now < $secondTues) {
echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A', $secondTues);
}
//If todays date greater than 2nd Tuesday 5pm and less that 4th Tuesday 11pm, display date for 4th Tuesday 5pm
elseif ($now > $secondTues and $now < $fourthTues) {
echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A', $fourthTues);
}
//If todays date greater than 4th Tuesday
elseif ($now > $fourthTues){
echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A', $nextTues);
}
else{
echo "foobar";
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="test">
Current Time: <?php echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A',$now); echo " " . $now;?></br>
First Tuesday: <?php echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A',$firstTues);echo " " . $firstTues;?></br>
Second Tuesday: <?php echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A',$secondTues);echo " " . $secondTues;?></br>
Fourth Tuesday: <?php echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A',$fourthTues);echo " " . $fourthTues;?></br>
Next Month First Tuesday: <?php echo date('F j\<\s\u\p\>S\</\s\u\p\> \a\t g:i A',$nextTues);echo " " . $nextTues;?>
</p>
<h2>Next Council Meeting:</h2>
<h1><?php nextCouncilMeeting()?></h1>
</body>
</html>
但是我的变量抛出一个未定义的错误,我做错了什么?
【问题讨论】:
-
谢谢@JonathanKuhn,我认为它一定是愚蠢的,把你的评论放在答案中,我会给你一些代表。另外,感谢您向我介绍该网站。
标签: php if-statement math var strtotime