开发者

Convert timestamp to readable date/time with PHP

开发者 https://www.devze.com 2023-01-28 19:30 出处:网络
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:

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

精彩评论

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