-
- //mktime()
- Convert date and time to unix timestamp
- //time()
- Get the unix timestamp of the current time
- echo date("Y-m-d",mktime(0 ,0,0,12,31,2013))."
";
-
- //Example: Calculate the age of a user by calculating the difference between two unix timestamps
-
- $year = 1991;
- //Suppose the user's date of birth is 1991.07.16
- $month = 07;
- $day = 16;
- $brithday = mktime(0,0,0,$month,$day,$year);
- //Replace the user Convert the date of birth to a unix timestamp
- $nowdate = time();
- //Get the unix timestamp of the current time
- $ageunix = $nowdate - $brithday;
- //Get the difference in timestamps
- $age = floor ($ageunix / (60*60*24*365));
- //The difference in timestamps divided by the number of seconds per year is the user's actual age
- echo "The user's age is ".$age."< ;br> The sunrise time of a certain day
- //date_sunset()
- The sunset time of a certain day
- //date()
- Format a local time and date
- //microtime()
- Return the current UNIX timestamp and microseconds
- / /The following class calculates the execution time of the program by obtaining the execution time of the two functions
- class Timer{
- private $startTime;
- private $stopTime;
- function __construct(){
- $this->startTime = 0;
- $this->stopTime = 0;
- }
- function start(){
- $this->startTime = microtime(true);
- }
- function stop(){
- $this->stopTime = microtime(true) ;
- }
- function spent(){
- return round(($this->startTime - $this->stopTime),4);
- }
- }
- $timer = new Timer();
- $timer-> ;start();
- usleep(1000);
- $timer->stop();
- echo "Time to execute script".$timer->spent()."seconds" ;
- ?>
-
-
-
- Copy code
-
-
-
-
-
PHP
|