开发者

Convert timestamp to readable date/time with PHP

I have a field in an MySQL database named last_login which is stored as an int(10). I would like to echo the last_login data as a readable date/time. Here is the code I currently have:

$timestamp = 1291575177;
echo date("h:i:s",$timestamp);

What is the proper way to add the last_login data from the MySQL database into the above code where the 129157517开发者_开发问答7 is?


Use this:

echo date('Y-m-d:H:i:s',1291575177);

The output of that would be 2010-12-05:18:52:57.


$connection = mysql_connect("...");

$result = mysql_query("SELECT timestamp FROM example_table LIMIT 1", $connection);
$row = mysql_fetch_assoc();
echo(date('Y-m-d H:i:s', intval($row['timestamp']))); // assuming that row['timestamp'] is a valid unix timestamp

mysql_close($connection);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜