php动态时间
Ⅰ 请教一个用php在网页上动态显示系统时间的代码
time()在php里就是当前的时间戳
你可以用date函数来格式化来输出时间。动态说白了就是1s或者更短更长的时间为间隔来刷新这个页面而已!
Ⅱ php中如何获得当前时间
一、使用函式 date() 实现
在编辑器中输入<?php echo $showtime=date("Y-m-d H:i:s");?>,点击回车就可以得知当前的时间。其中Y是代表4位的年份,H是24小时制,i 是分钟,如: "00" 至 "59" 。s -是秒,如: "00" 至 "59" 。
d 是几日,二位数字,若不足二位则前面补零。 如: "01" 至 "31" 。m代表月份,二位数字,若不足二位则在前面补零,如: "01" 至 "12" 。
二、使用time函数
在编辑器中输入echo date("y-m-d",$time)点击回车就可以得知当前的时间,其中Y是代表4位的年份,m代表月份,二位数字,若不足二位则在前面补零,如: "01" 至 "12" 。d 是几日,二位数字,若不足二位则前面补零。 如: "01" 至 "31" 。
三、使用strftime函数
在编辑器中输入echo strftime ("%hh%m %a %d %b" ,time());点击回车就可以得知当前的时间。
(2)php动态时间扩展阅读:
Date/Time 函数
一、time — 返回当前的 Unix 时间戳
二、timezone_abbreviations_list — 别名 DateTimeZone::listAbbreviations
三、timezone_identifiers_list — 别名 DateTimeZone::listIdentifiers
四、timezone_location_get — 别名 DateTimeZone::getLocation
五、date — 格式化一个本地时间/日期
六、getdate — 取得日期/时间信息
七、gettimeofday — 取得当前时间
八、gmdate — 格式化一个 GMT/UTC 日期/时间
九、gmmktime — 取得 GMT 日期的 UNIX 时间戳
Ⅲ 用php如何实现在网页显示动态时间
php只能输出一次,页面不停动态显示时间,还是需要js来干这事,给你段代码,你看看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function showTime(){
nowtime=new Date();
year=nowtime.getFullYear();
month=nowtime.getMonth()+1;
date=nowtime.getDate();
document.getElementById("mytime").innerText=year+"年"+month+"月"+date+" "+nowtime.toLocaleTimeString();
}
setInterval("showTime()",1000);
</script>
</head>
<body>
<span id="mytime"></span>
</body>
</html>
使用定时器,1秒显示一次
Ⅳ PHP 如何让时间自动更新
方法有两种:
方法一
(1.WINDOW 定时调用PHP脚本:
do
set ws=createobject("wscript.shell")
ws.run"D:\php\php.exe D:\php\source\do.php",vbhide
wscript.sleep 5000 '毫秒
loop新建文本文件,复制以上脚本,另存为后缀为*(.vbs)的文件后即可;
(2.下载PHP,解压到D:
php.ini-dist重命名为php.ini,
修改PHP.ini里面的 extension_dir = “D:\php\ext\”
新建
\source\do.php
就可以定时执行do.php了。
方法二
使用死循环
如:
http://www.lianglong.cq.cn/post/320.html
set_time_limit(0);
ignore_user_abort(true);
Ⅳ php显示当前时间 并且随时变化
php的几种获取当前时间的函数
方法一date函数
echo date(‘y-m-d h:i:s’,time());
//2010-08-29 11:25:26
方法二 time函数
$time = time();
echo date("y-m-d",$time) //2010-08-29
方法三 $_server['server_time']
方法四 strftime
echo strftime ("%hh%m %a %d %b" ,time());
18h24 sunday 21 may
还有一个问题就是时区问题,php环境默认时差与北京时间相差8小时,我们要想获取正确的时间就必须设置
在php文件开始处 加上date_default_timezone_set('prc');
或在php.ini里面 date.timezone=prc;嗾。
记得修改了php.ini要重起apache
Ⅵ php 输出时间。格式为:“时:分:秒.毫秒”,例如:19:37:05.380,要用什么函数怎么实现
<?php
function udate($format = 'u', $utimestamp = null) {
if (is_null($utimestamp))
$utimestamp = microtime(true);
$timestamp = floor($utimestamp);
$milliseconds = round(($utimestamp - $timestamp) * 1000000);
return date(preg_replace('`(?<!\\)u`', $milliseconds, $format), $timestamp);
}
echo udate('Y-m-d H:i:s.u');
?>