date_default_timezone_set('Europe/London');
$date = '06-17-2013';
if (strtotime("now") > strtotime("+5 days", strtotime($date))) {
echo '5 days have gone by';
} else {
echo 'not yet';
}这个函数总是返回'5天已经过去了‘。我永远不能让它返回“还没有”为什么?
发布于 2013-06-18 23:58:32
请尝试使用YYYY-MM-DD指定日期。strtotime似乎不支持MM-DD-YYYY表示法。
发布于 2013-06-19 00:00:54
您应该考虑使用SPL DateTime对象。
试试这个:
$date = new DateTime('2013-06-17');
$date->add(new DateInterval("P5D");
$now = new DateTime();
if($now > $date) {
echo "5 Days have passed";
}
else{
echo "not yet";
}发布于 2013-06-19 00:19:20
如果您将'06-17-2013'更改为此'06/17/2013',它将按预期工作
<?php
date_default_timezone_set('Europe/London');
$date = '06/17/2013';
if (strtotime("now") > strtotime("+5 days", strtotime($date))) {
echo '5 days have gone by';
} else {
echo 'not yet';
}
?>在strtotime函数中使用正斜杠/和连字符-是不同的。
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator
between the various components: if the separator is a slash (/), then the American
m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the
European d-m-y format is assumed.https://stackoverflow.com/questions/17173468
复制相似问题