Home  >  Article  >  Backend Development  >  Detailed explanation of PHP time() function to obtain the current timestamp instance

Detailed explanation of PHP time() function to obtain the current timestamp instance

怪我咯
怪我咯Original
2017-04-17 15:38:277020browse

We learned about the mktime() function earlier, and we know that the mktime() function returns a UNIX timestamp based on the given parameters. When the mktime() function does not fill in the parameters, it returns the current timestamp

as follows:

However, the main function of the mktime() function is not to return the current timestamp Time, but formatted time, so in PHP, we are specifically provided with a function to obtain the current timestamp, which is the time() function

# we are going to explain in this chapter.

##Usage of time() function

In PHP, the current UNIX timestamp is obtained through the time() function. The return value is from the timestamp epoch (Greenwich Mean Time 1970 1 00:00:00 on the 1st of the month) to the current number of seconds.

His syntax is as follows:

time()

Detailed syntax explanation:

The time() function has no parameters and the return value is the integer value of the UNIX timestamp.

The usage is as follows:

Detailed explanation of PHP time() function to obtain the current timestamp instancetime() function is to obtain the current timestamp. What is obtained is an integer. We format it as follows

date("Y-m-d H:i:s", time()) ;

Let’s use an example to illustrate

Get the current timestamp instance

In this example, we use the time() function to get the current local timestamp, and Format the timestamp and output it. The code is as follows

";                   //输出当前日期

echo 'Next time:'.date("Y-m-d",$nexttime);           //输出变量$nexttime的日期
?>

The code running result is as follows:

Detailed explanation of PHP time() function to obtain the current timestamp instance

The above is a simple example of using the time() function to obtain the current timestamp, and the date() function is to obtain The current time and date. In the next section, we will explain the usage of the date function.



The above is the detailed content of Detailed explanation of PHP time() function to obtain the current timestamp instance. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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