Analysis of php time function usage and php function usage. Php time function usage analysis. This article describes the usage of php time functions. For your reference, refer to: Analysis on the usage of php time functions related to unix timestamps in php and the usage of php functions.
This example describes the usage of php time functions. We will share this with you for your reference. The details are as follows:
Functions related to unix timestamps in php are easy to use.
Time () returns the current Unix timestamp.
Microtime -- returns the current Unix timestamp and microseconds.
Example 1. run the script with 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 () gets the Unix timestamp of a date.
Int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst])
The parameter can be omitted from the right to the left. any omitted parameter is set to the current value of the local date and time.
Date () format a local time/date
String date (string format [, int timestamp])
Tip: Since PHP 5.1, the timestamp at which the REQUEST is initiated is saved in $ _ SERVER ['request _ time.
Strtotime -- parses the date and time descriptions of any English text into Unix timestamps
echo strtotime("+1 day"), "/n";echo strtotime("+1 week"), "/n";
Example 2. the last day of a certain time, and the last month
strtotime("+1 day ".$day);strtotime("2008-01-31 +1 month");strtotime($day." +1 day");
The above format is correct
PS: This site also provides a Unix timestamp conversion tool, which is very useful for your reference:
Unix timestamp conversion tool:
Http://tools.jb51.net/code/unixtime
We recommend a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
In addition, because 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 tools:
Http://tools.jb51.net/code/ccode_html_css_json