PHP time processing function
Release: 2016-07-25 08:42:59
Original
709 people have browsed it
-
- //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
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31