The addition and subtraction operations on time convert the time to the unix timestamp, and then perform addition and subtraction operations, and then perform reverse operations, php has a function to convert the time in the string format to the unix timestamp. The following is a simple example to add or subtract time, convert Time to unix timestamp, then perform addition and subtraction, and then perform reverse operations, php has a function to convert the time in the string format to the unix timestamp. The following is a simple example:
// Set the default time zone to use. Available after PHP5.1
Date_default_timezone_set ('Asia/Chongqing '); // used in China
Echo date ("Y-m-d H: I: s"); // display the current time
// Simple time addition and subtraction
$ Tomorrow = mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y"); // tomorrow
// The current result is a timestamp. it is formatted and displayed, and the following is the same
Echo date ("Y-m-d H: I: s", $ tomorrow );
$ Lastmonth = mktime (0, 0, 0, date ("m")-1, date ("d"), date ("Y"); // next month
$ Nextyear = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y") + 1); // tomorrow
// Returns the current Unix timestamp.
Echo time ();
// Returns the current Unix timestamp and microsecond ()
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 ();
|