我有这个代码,我在Datetime()有问题,如果我在我的数据库中获得时间戳他工作正常但是在转到另一个页面并且每次计数器返回到1 seconde并开始计数时返回到此页面代码再次
但是直接使用时间戳就像这个计数器一样正常
$then = new DateTime('2016-03-18 23:47:41' , new DateTimeZone('Europe/London'));
在数据库中获取时间戳时的此代码 e_time列给他时间戳类型
<?php
$stmt = $DB_con->prepare("SELECT * FROM `post` WHERE `e_stauts`=1 AND `lockin`=1 ORDER BY `id` DESC");
$stmt->execute();
}
foreach ($stmt->fetchAll() as $row) {
echo"".$row['e_title']." </br>";
$then = new DateTime(''.$row['e_time'].'' , new DateTimeZone('Europe/London'));
$now = new DateTime();
$delta = $now->diff($then);
$quantities = array(
'year' => $delta->y,
'month' => $delta->m,
'day' => $delta->d,
'hour' => $delta->h,
'minute' => $delta->i,
'second' => $delta->s);
if($quantities['day'] != 0){
echo "".$quantities['day']." Day ".'</br>';
}elseif($quantities['day'] == 0 & $quantities['hour'] > 0){
echo "".$quantities['hour']." Hour ".'</br>';
}elseif($quantities['hour'] == 0 & $quantities['minute'] > 0){
echo "".$quantities['minute']." Minute ".'</br>';
}elseif($quantities['minute'] == 0 & $quantities['second'] > 0){
echo "".$quantities['second']." Seconde ".'</br>';
}
}