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!