echo ($timestamp)
给"2012-05-03 15:35:46"
PHP 命令看起来像这样:"if $timestamp is older than 12 weeks then…"
谢谢你的帮助!
echo ($timestamp)
给"2012-05-03 15:35:46"
PHP 命令看起来像这样:"if $timestamp is older than 12 weeks then…"
谢谢你的帮助!
你需要的是strtotime()
!
$timestamp = strtotime($timestamp);
$twelveWeeksAgo = strtotime('-12 weeks');
if($timestamp < $twelveWeeksAgo) {
// do something
}
有多种检查方法,恕我直言,这是最能说明问题的。
如果您使用的是 php > 5.2,则可以使用 DateTime 和 DateInterval 对象:
$now = new DateTime();
$before = bew DateTime("2012-05-03 15:35:46");
$diff = $now->diff($before);
if ($diff->d > (12 * 7)) {
print "Older than 12 weeks";
}
请参阅此处的上述对象的文档。
$time_to_compare = new DateTime();
$twelve_weeks_ago = new DateTime ("-12 weeks");
if ($time_to_compare < $twelve_weeks_ago)
{
// Do stuff
}