dpwqicw157673 2016-03-19 00:02
浏览 113

时间戳问题PHP

i have this code and i have problem in Datetime() if i get timestamp in my database he working fine but after go to another page and come back to this page code every time the counter come back to 1 seconde and starts counting again

but when use the timestamp directly like this counter work fine

$then = new DateTime('2016-03-18 23:47:41' , new DateTimeZone('Europe/London'));

this code when get timestamp in database e_time column give him timestamp type

 <?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>';    
    }
     }     
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入