<?php
/*
*文件名:pageExeObj.php
*作用:取得页面执行时间
*参数:
*返回:页面执行时间(单位为秒)
*使用:
$timer = new pageExeObj;
$timer->start();
你的代码放在此处
$timer->stop();
echo "执行本SCRIPT共".$timer->spent()."秒";
作者:不祥 greenskys最后整理
*/
class pageExeObj {
var $StartTime = 0;
var $StopTime = 0;
var $TimeSpent = 0;
function start()
{
$this->StartTime = microtime();
}
function stop()
{
$this->StopTime = microtime();
}
function spent()
{
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
$StartMicro = substr($this->StartTime,0,10);
$StartSecond = substr($this->StartTime,11,10);
$StopMicro = substr($this->StopTime,0,10);
$StopSecond = substr($this->StopTime,11,10);
$start = doubleval($StartMicro) + $StartSecond;
$stop = doubleval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return substr($this->TimeSpent,0,8);
}
} // end function spent();
} //end class timer;
$timer = new pageExeObj;
$timer->start();
echo date_default_timezone_get();//返回默认时区
echo "<br>";
date_default_timezone_set("Asia/Shanghai");//设置默认时区
echo "<br>";
echo time();
echo "<br>";
echo date("Y-m-d H:i:s");
echo "<br>";
echo date("l"); //表示周里的某天
echo "<br>";
echo date("H:i:sa");
echo "<br>";
echo date("Y-m-d H:i:s"); //a - 小写的午前和午后(am 或 pm)
//mktime(hour,minute,second,month,day,year)
//mktime() 函数对于日期运算和验证非常有用。它可以自动校正越界的输入
echo "<br>";
$d=mktime(9, 12, 31, 6, 10, 2015);
echo "创建日期是 " . date("Y-m-d h:i:sa", $d);
echo "<br>";
echo(date("M-d-Y",mktime(0,0,0,12,36,2001)))."<br>";
echo(date("M-d-Y",mktime(0,0,0,14,1,2001)))."<br>";
echo(date("M-d-Y",mktime(0,0,0,1,1,2001)))."<br>";
echo(date("M-d-Y",mktime(0,0,0,1,1,99)))."<br>";
echo "<br>";
$d=strtotime("tomorrow");
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "<br>";
$d=strtotime("next Saturday");
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "<br>";
$d=strtotime("+3 Months");
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "<br>";
$d=strtotime("+1 Day");
echo date("Y-m-d h:i:sa", $d) . "<br>";
$d=strtotime("+2 Days");
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "<br>";
$startdate=strtotime("Saturday");
$enddate=strtotime("+6 weeks",$startdate);
while ($startdate < $enddate) {
echo date("M d", $startdate),"<br>";
$startdate = strtotime("+1 week", $startdate);
}
$d1=strtotime("December 31");
$d2=ceil(($d1-time())/60/60/24);
echo "距离十二月三十一日还有:" . $d2 ." 天。<br>";
//checkdate判断日期是否有效
var_dump(checkdate(12,31,2000));
echo "<br>";
var_dump(checkdate(2,29,2004));
echo "<br>";
var_dump(checkdate(2,29,2014));
echo "<pre>";
print_r(getdate());//返回一个根据 timestamp 得出的包含有日期信息的结合数组。如果没有给出时间戳,则认为是当前本地时间。
echo "</pre>";
echo date("U"); //大写U返回当前时间戳
echo "<br>";
$my_t=getdate(date("U"));
echo "<pre>";
print_r($my_t);
echo "</pre>";
print_r("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");
for($i=1;$i<10000;$i++){
//echo $i."<br>";
}
$timer->stop();
echo "执行本SCRIPT共".$timer->spent()."秒";
//date(format,timestamp)
?>