如何获得准确的时区显示"你在几天前/小时前回答#34;?

时间:2014-10-23 13:26:00

标签: php mysql

我来自韩国,我的时区是GMT + 9

如果发布任何评论22-10-2014(我不知道如何获得白天(上午/下午))

<?php

$date = date_parse_from_format('d-m-Y', '22-10-2014');

$timestamp = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);

$current_time   = time();

$time=$current_time-$timestamp;

echo "<br/>diff ".$time;

?>

从上面我可能会根据$ time得到多少秒/分钟/小时。但是如何在服务器上(世界上任何地方)留下时区?如何确定当天发布的确切时间,以便我可以说,这篇文章是在(s / m / h / d /周/月/年)之前发布的。

这是我尝试使用mysql ...

   <?php
   $current_time=time();
   //echo time(); 

   $postdate=date("d-m-Y ");
   $date = date_parse_from_format('d-m-Y', $postdate);
   //echo"<br/> date". $postdate;
   $timestamp = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
   //echo"<br/> timestamp". $timestamp;

    $insert =mysql_query("UPDATE time SET time = '$timestamp' WHERE username='madhusudan'");

    $call=mysql_query("SELECT * FROM time WHERE username='madhusudan'");
       while($num=mysql_fetch_assoc($call)){
       $time_db=$num['time'];

       }
    $time=$current_time-$time_db;
    echo $time;

    ?>


input date=23-10-2014
data inserted in database=1414015200


Result
$time=54769 


But, I inserted just few second ago??????

How to solve it Bro.....

0 个答案:

没有答案