The examples in this article describe the usage of php time function. Share it with everyone for your reference, the details are as follows:
There are unix timestamp related operation functions in php, 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 a 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() formats a local time/date
string date ( string format [, int timestamp] )
Tip: Since PHP 5.1, the timestamp of the time when the request was initiated is saved in $_SERVER['REQUEST_TIME'].
strtotime -- Parse any English text datetime description into a Unix timestamp
echo strtotime("+1 day"), "/n"; echo strtotime("+1 week"), "/n";
Example 2. The day after a certain time, the month after a certain time
strtotime("+1 day ".$day); strtotime("2008-01-31 +1 month"); strtotime($day." +1 day");
The above forms are correct
PS: This site also provides a Unix timestamp conversion tool, which is very practical and is provided for your reference:
Unix timestamp (timestamp) conversion tool:
http://tools.jb51.net/code/unixtime
Here we recommend a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
In addition, since php belongs to the C language style, the following tool can also format php code:
C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP mathematical operation skills", "Summary of PHP operating office document skills (including word, excel, access, ppt)", "PHP array ( Array) operating skills collection", "php sorting algorithm summary", "php common traversal algorithms and techniques summary", "php data structure and algorithm tutorial", "php programming algorithm summary", "php regular expression usage summary", "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"
I hope this article will be helpful to everyone in PHP programming.