PHPtime () function to obtain the current timestamp instance details

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.