我正在检查帖子是否过期,以下是我迄今为止尝试的
$p = "08"; //suppose month is Aug
$m="2016"; //year is 2016
$input_time = mktime(0,0,0,$p+1,0,$m);
if ($input_time < time()){
print '<p class = "error">Post has expired</p>';
}
else{
echo 'Post is still fresh';
}
在上面的例子中,我只能检查月份;年,我怎么也可以检查日、月和;年
使用strtotime
$curdate = strtotime('05-08-2016');
$mydate = strtotime('04-08-2016');
if($curdate > $mydate)
{
echo 'Post is Expired';
}
您可以使用DateTime
$date = new DateTime('2016-09', new DateTimeZone('Europe/London'));
var_dump($date->getTimestamp()<time()); //true
$date = new DateTime('2016-09', new DateTimeZone('Europe/London'));
var_dump($date->getTimestamp()<time()); //false
$date = new DateTime('2016-08-06', new DateTimeZone('Europe/London'));
var_dump($date->getTimestamp()<time()); //false
$date = new DateTime('2016-08-04', new DateTimeZone('Europe/London'));
var_dump($date->getTimestamp()<time()); //true
使用strtotime("input time");
并将其用于检查
如果我有你的问题,解决方案很容易。只需通过第五个参数中的一天而不是零:
$d='12';
$input_time = mktime(0,0,0,$p+1,$d,$m);