In PHP, the time () function is used to obtain the current UNIX Timestamp. the returned value is from the timestamp epoch (00:00:00 GMT, January 1, January 1, 1970) to the current number of seconds. We have learned the mktime () function before and know that the mktime () function returns the UNIX timestamp based on the given parameters. If the mktime () function does not specify a parameter, the current timestamp is returned.
As shown below:
However, the main function of the mktime () function is not to return the current time, but to format the time. Therefore, in PHP, a function is provided to obtain the current timestamp, that is what we will explain in this chapter.Time () function
Usage of the time () function
In PHP, the time () function is used to obtain the current UNIX Timestamp. the returned value is from the timestamp epoch (00:00:00 GMT, January 1, January 1, 1970) to the current number of seconds.
The syntax is as follows:
time()
Syntax explanation:
The time () function does not have a parameter. The return value is the integer of the UNIX timestamp.
The usage is as follows:
The time () function obtains the current timestamp and an integer. We format it, as shown below:
date("Y-m-d H:i:s", time()) ;
The following is an example.
Obtains the current timestamp instance.
In this example, we use the time () function to obtain the current local timestamp and format the timestamp. The code is as follows:
"; // Output the current date echo 'next time: '. date (" Y-m-d ", $ nexttime); // output the date of the variable $ nexttime?>
The code execution result is as follows:
The preceding example uses the time () function to obtain the current timestamp. the date () function is used to obtain the current time and date. in the next section, we will explain how to use the date function.
The above is the detailed description of the current timestamp instance obtained by The PHP time () function. For more information, see other related articles in the first PHP community!