PHPdate () function to obtain the current date and time instance details

Source: Internet
Author: User
When we explain how to obtain the current timestamp instance, we use the date () function to obtain the current time and date. This chapter will introduce it to you, returns the "date" function of the current date and time. In PHP, the date () function is used to obtain the current time and date. The syntax format is as follows, we used Date () functionThis section describes how to obtain the "date" function of the current date and time.

Date function usage

In PHP, use the date () function to obtain the current time and date. The syntax format is as follows:

date(format,timestamp);

The date () function returns the string generated by the timestamp parameter in the specified format. the timestamp parameter is optional. If this parameter is not specified, the current time is used. The format parameter allows developers to output dates in the specified format. For details about formatting, we have written several chapters specifically. here we can refer to php-weizijiaocheng-360500.html.

Here are some predefined constants of time and date, as shown in the following table. these constants provide standard date expressions for date format functions.

Predefined Constants of time and date

Predefined Constants Description
DATE_ATOM Atomic clock format
DATE_COOKIE HTTP Cookies
DATE_ISO8601 ISO-8601 format
DATE_RFC822 RFC822 format
DATE_RFC850 RFC850 format
DATE_RSS WORSS format
DATE_W3C World Wide Web Consortium format

The following example shows the differences between constants.

Date function Example 1

This example shows how to use the date () function. the code is as follows:

 "; // Output the current date?>

Code running result:

Date function Example 2

This example compares the output of various constants. the sample code is as follows:

 ";echo "DATE_COOKIE=".date(DATE_COOKIE)."
";echo "DATE_ISO8601=".date(DATE_ISO8601)."
";echo "DATE_RFC822=".date(DATE_RFC822)."
";echo "DATE_RFC850=".date(DATE_RFC850)."
";echo "DATE_RSS=".date(DATE_RSS)."
";echo "DATE_W3C=".date(DATE_W3C );?>

Code running result:

The above is the output of the predefined constant. Next section describes how to obtain date information in PHP.

The above is the detailed description of the current date and time instance obtained by The PHP date () 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.