1、date("Y-m-d H:i:s");//php中用一句话就能获取当前显示时间
2、js中获取当前时间:
<script language="javaScript">
var now= new Date( );
var hour = now.getHours( );
if (hour>=0 && hour <=12)
document.write("上午好!");
if (hour>12 && hour<= 18)
document.write("下午好!");
if (hour>18 && hour <24)
document.write("晚上好!");
document.write("<P>今天日期:"+now.getFullYear()+"年"
+(now.getMonth( )+1)+"月"+now.getDate()+"日");
document.write("<P>现在时间:"+now.getHours()+"点"+now.getMinutes( )+"分");
</script>
3、利用setTimeout("time()",1000)让时间走起来,这个与上面的区别是上面的是获取当前的时间,时间不在走动,这个是它一直走,没有停
<script language="javascript">
function time()
{for(i=0;i<=10000;i++)
for(j=0;j<=100;j++)
var now=new Date();
var hour=now.getHours();
var hel;
document.form1.y.value=now.getFullYear();
document.form1.m.value=now.getMonth( );
document.form1.date.value=now.getDate();
document.form1.day.value=now.getDay();
document.form1.h.value=now.getHours();
document.form1.mi.value=now.getMinutes();
document.form1.sec.value=now.getSeconds();
if(hour>=6&&hour<12) hel="上午好!";
if(hour>=12&&hour<18)hel="下午好!";
if((hour>=18&&hour<=23)||(hour>=0&&hour<6)) hel="晚上好!" ;
document.form1.hello.value=hel;
setTimeout("time()",1000);
}
</script>
</head>
<body onload="time()">
<form name="form1">
大家:<input name="hello" type="text"><br>
今天是<input name="y" type="text">年
<input name="m" type="text">月<input name="date" type="text">日星期<input name="day"
type="text"><input name="h" type="text">时<input name="mi" type="text">分<input name="sec"
type="text">秒
</form>
</body>