日期:2011-06-05 浏览次数:20513 次
注意本程序中使用的表结构为:
use test;
create table datetime(dtfield datetime);
insert into datetime values(now());
*/
?>
<?
$server = mysql_connect("localhost","test","") or die("无法连接数据库服务器!");
$db = mysql_select_db("test",$server) or die("无法连接test数据库!");
$sql = "select unix_timestamp(dtfield) from datetime";
$rst = mysql_query($sql) or die("查询失败:$sql");
$row = mysql_fetch_array($rst) or die("无法取得数据!");
$datetime = $row["unix_timestamp(dtfield)"];
$now = time();
$diff = $now-$datetime;
$diffhour = (int)($diff/3600);
$diffminute = (int)(($diff-$diffhour*3600)/60);
$diffsecond = $diff-$diffhour*3600-$diffminute*60;
echo "当前时间为 : " . date("Y年m月d日 H:i:s",$now) .&n