datetime utc格式,显示问题

时间:2014-04-09 07:14:49

标签: php datetime utc

我不知道它出了什么问题,当插入评论时它没有正确回显,它显示的是44年前 是否写入使用日期('Y-m-d H:i:s')作为日期时间类型插入评论

以及如何以utc格式存储数据

这是我的插入代码

 $conn = new PDO('mysql:host=localhost;dbname=db', 'root', '');
          $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $query = "INSERT INTO comp_pt_comments(cat_id, post_id, commented_by, delete_flag, last_modified, comments)
            VALUES (?,?,?,'false',date('Y-m-d H:i:s'),?)";
          $stmt = $conn->prepare($query);
          $stmt->bindParam(1, $cat_id);
          $stmt->bindParam(2, $post_id);
          $stmt->bindParam(3, $commented_by);
          $stmt->bindParam(4, $comments);

          $stmt->execute(); 
          $count=$stmt->rowCount();
          $stmt->closeCursor();  
下面是我的回声

while( $row = mysql_fetch_array($comments_result) ){

        $temp=array("comment_id"=>$row['sno'],"commented_by"=>$row['commented_by'],"comments"=>$row['comments'],"cmnt_user_img"=>$row['image_path'],"posted_time"=>$row['last_modified'],"commented_user"=>$row['cmmnts_usr'],"reply_count"=>$row['reply_count']);
        $comments_array[$i]=$temp;
        $i++;

    }

echo time_elapsed_string($comments_array[$j]['posted_time']);

这是我用过的功能

define("SECOND", 1);
define("MINUTE", 60 * SECOND);
define("HOUR", 60 * MINUTE);
define("DAY", 24 * HOUR);
define("MONTH", 30 * DAY);
function time_elapsed_string($time)
{   

$delta = time() - $time;

if ($delta < 1 * MINUTE)
{
    return $delta == 1 ? 'one second ago' : $delta . ' seconds ago';
}
if ($delta < 2 * MINUTE)
{
  return 'a minute ago';
}
if ($delta < 45 * MINUTE)
{
    return floor($delta / MINUTE) . ' minutes ago';
}
if ($delta < 90 * MINUTE)
{
  return 'an hour ago';
}
if ($delta < 24 * HOUR)
{
  return floor($delta / HOUR) . ' hours ago';
}
if ($delta < 48 * HOUR)
{
  return 'yesterday';
}
if ($delta < 30 * DAY)
{
    return floor($delta / DAY) . ' days ago';
}
if ($delta < 12 * MONTH)
{
  $months = floor($delta / DAY / 30);
  return $months <= 1 ? 'one month ago' : $months . ' months ago';
}
else
{
    $years = floor($delta / DAY / 365);
    return $years <= 1 ? 'one year ago' : $years . ' years ago';
}
} 

0 个答案:

没有答案