本文實例講述了php時間函數用法。分享給大家供大家參考,具體如下:
php中有unix時間戳的 相關操作函數,使用很方便
time() 返回當前的 Unix 時間戳
microtime -- 返回當前 Unix 時間戳和微秒數
例 1. 用 microtime() 對腳本的運行計時
<?php/*** Simple function to replicate PHP 5 behaviour*/function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec);}$time_start = microtime_float();// Sleep for a whileusleep(100);$time_end = microtime_float();$time = $time_end - $time_start;echo "Did nothing in $time seconds/n";?> mktime()取得一個日期的 Unix 時間戳
int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
參數可以從右向左省略,任何省略的參數會被設置成本地日期和時間的當前值
date()格式化一個本地時間/日期
string date ( string format [, int timestamp] )
提示: 自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了發起該請求時刻的時間戳。
strtotime -- 將任何英文文本的日期時間描述解析為 Unix 時間戳
echo strtotime("+1 day"), "/n";echo strtotime("+1 week"), "/n"; 例2. 某個時間的后一天,后一月
strtotime("+1 day ".$day);strtotime("2008-01-31 +1 month");strtotime($day." +1 day"); 以上形式都正確















