This article mainly introduces the usage of PHP time function, and analyzes the usage of PHP timestamp related functions time, mktime, date and strtotime in the form of examples. It is very simple and practical. Friends who need it can refer to it
php has unix timestamp related operation functions, which are very convenient to use
time() returns the current Unix timestamp
microtime - - Returns the current Unix timestamp and microseconds
Example 1. Use microtime() to time the execution of the script
<?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 while usleep(100); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Did nothing in $time seconds/n"; ?>
mktime() Gets the Unix timestamp of a date
int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
Parameters can be omitted from right to left. Any omitted parameter will be set to the current value of the local date and time
date( )Format a local time/date
string date ( string format [, int timestamp] )
Tip: Save in $_SERVER['REQUEST_TIME'] since PHP 5.1 The timestamp of the time when the request was initiated.
strtotime -- Parse the date and time description of any English text into a Unix timestamp
echo strtotime("+1 day"), "/n"; echo strtotime("+1 week"), "/n";
Example 2. A certain time The day after, the month after
strtotime("+1 day ".$day); strtotime("2008-01-31 +1 month"); strtotime($day." +1 day");
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP Ajax JavaScript Json method to obtain weather information
php Code to check the validity of the proxy ip
PHP method to control the front-end pop-up dialog box
The above is the detailed content of Usage and example analysis of php time function. For more information, please follow other related articles on the PHP Chinese website!