Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当用户发布内容时,如何更改mysql时间戳的格式_Php_Mysql_Date_Timestamp - Fatal编程技术网

Php 当用户发布内容时,如何更改mysql时间戳的格式

Php 当用户发布内容时,如何更改mysql时间戳的格式,php,mysql,date,timestamp,Php,Mysql,Date,Timestamp,当前,无论何时回显时间戳,它都是这样的 function show_posts($userid){ $posts = array(); $sql = "select body, stamp from posts where user_id = '$userid' order by stamp desc"; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ $posts[] = array(

当前,无论何时回显时间戳,它都是这样的

function show_posts($userid){
$posts = array();
$sql = "select body, stamp from posts where user_id = '$userid' order by stamp desc";
$result = mysql_query($sql);
while($data = mysql_fetch_object($result)){
    $posts[] = array(   'stamp' => $data->stamp, 
                        'userid' => $userid, 
                        'body' => $data->body
                );
}
return $posts;
}
我想把这张邮票换成这样,而不是打印2012-03-26 12:07:52 它将打印日期,然后是时间等。下面是我在网页上显示它的方式

<?php
        foreach ($posts as $key => $list){
            echo "<tr valign='top'>\n";
            echo "<td>".$list['userid'] ."</td>\n";
            echo "<td>".$list['body'] ."<br/>\n";
            echo "<small>".$list['stamp']."<br/>\n <a>Like</a> <a>Flag</a><hr     class='span9'/></small></td>\n";
            echo "</tr>\n";
        }
?>

使用。

使用将字符串转换为时间戳,然后使用将其格式化为您想要的格式。

使用日期(格式化,时间戳)功能。关于格式选项和如何使用函数的更多信息:我认为这是最简单的方法,不会使MySQL查询复杂化。strotime()将返回一个unix时间戳,它为您提供无限格式选项。回显日期('fd',strottime($timevarfrommysql));这就是一个例子。